yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.tool.service.impl;
 
import java.io.File;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
 
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
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.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.entity.Workstation;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.system.entity.BasCodeRule;
import com.qianwen.smartman.modules.system.service.IBasCoderuleService;
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
import com.qianwen.smartman.modules.tool.convert.ToolManageConvert;
import com.qianwen.smartman.modules.tool.entity.Tool;
import com.qianwen.smartman.modules.tool.entity.ToolCategory;
import com.qianwen.smartman.modules.tool.entity.ToolModel;
import com.qianwen.smartman.modules.tool.entity.ToolParameter;
import com.qianwen.smartman.modules.tool.enums.ToolLifeCountMethodEnum;
import com.qianwen.smartman.modules.tool.enums.ToolLifeStateEnum;
import com.qianwen.smartman.modules.tool.enums.ToolUseStateEnum;
import com.qianwen.smartman.modules.tool.excel.ToolManageExcel;
import com.qianwen.smartman.modules.tool.interceptor.CustomCellWriteHandler;
import com.qianwen.smartman.modules.tool.mapper.ToolManageMapper;
import com.qianwen.smartman.modules.tool.service.IToolCategoryService;
import com.qianwen.smartman.modules.tool.service.IToolChangeRecordService;
import com.qianwen.smartman.modules.tool.service.IToolManageService;
import com.qianwen.smartman.modules.tool.service.IToolModelService;
import com.qianwen.smartman.modules.tool.service.IToolParameterService;
import com.qianwen.smartman.modules.tool.vo.ToolDischargeVO;
import com.qianwen.smartman.modules.tool.vo.ToolManageEquipmentVO;
import com.qianwen.smartman.modules.tool.vo.ToolManageSaveVO;
import com.qianwen.smartman.modules.tool.vo.ToolManageTreeVO;
import com.qianwen.smartman.modules.tool.vo.ToolManageUpdateVO;
import com.qianwen.smartman.modules.tool.vo.ToolManageVO;
import com.qianwen.smartman.modules.tool.vo.ToolQueryVO;
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/tool/service/impl/ToolManageServiceImpl.class */
public class ToolManageServiceImpl extends BaseServiceImpl<ToolManageMapper, Tool> implements IToolManageService {
    private static final Logger log = LoggerFactory.getLogger(ToolManageServiceImpl.class);
    private final IToolCategoryService toolCategoryService;
    private final IToolModelService toolModelService;
    private final IWorkstationService workstationService;
    private final IToolChangeRecordService toolChangeRecordService;
    private final IEmployeeService employeeService;
    private final ICodeGeneratorService codeGeneratorService;
    private final IBasCoderuleService basCoderuleService;
    private final OssBuilder ossBuilder;
    private final IToolParameterService toolParameterService;
    private static final String TOOL_EXCEL_NAME = "刀具状态报表";
 
 
    public ToolManageServiceImpl(final IToolCategoryService toolCategoryService, final IToolModelService toolModelService, final IWorkstationService workstationService, final IToolChangeRecordService toolChangeRecordService, final IEmployeeService employeeService, final ICodeGeneratorService codeGeneratorService, final IBasCoderuleService basCoderuleService, final OssBuilder ossBuilder, final IToolParameterService toolParameterService) {
        this.toolCategoryService = toolCategoryService;
        this.toolModelService = toolModelService;
        this.workstationService = workstationService;
        this.toolChangeRecordService = toolChangeRecordService;
        this.employeeService = employeeService;
        this.codeGeneratorService = codeGeneratorService;
        this.basCoderuleService = basCoderuleService;
        this.ossBuilder = ossBuilder;
        this.toolParameterService = toolParameterService;
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public Boolean saveTool(ToolManageSaveVO toolManageSaveVO) {
        Set<String> toolManageCodeSet = list().stream().map((v0) -> {
            return v0.getCode();
        }).collect(Collectors.toSet());
        ToolModel toolModel = this.toolModelService.getOne(Lambda.eq((v0) -> {
            return v0.getId();
        }, toolManageSaveVO.getToolModelId()));
        Tool toolManage = ToolManageConvert.INSTANCE.saveVOToConvert(toolManageSaveVO);
        toolManage.setToolPrefixCode(toolModel.getToolPrefixCode());
        toolManage.setUseState(ToolUseStateEnum.ADD.getCode());
        if (Func.isNotEmpty(toolManage.getCode()) && toolManageCodeSet.contains(toolManage.getCode())) {
            throw new ServiceException(MessageUtils.message("tool.tool.code.is.exist", new Object[0]));
        }
        if (Func.isEmpty(toolManageSaveVO.getCode())) {
            toolManageSaveVO.setToolCategory(String.valueOf(toolModel.getToolCategoryId()));
            do {
                toolManage.setCode(this.codeGeneratorService.getGeneratorCode(toolManageSaveVO, MetaTypeEnum.TOOL_MANAGE.getCode()));
            } while (toolManageCodeSet.contains(toolManage.getCode()));
            return Boolean.valueOf(save(toolManage));
        }
        return Boolean.valueOf(save(toolManage));
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public Boolean updateTool(ToolManageUpdateVO toolManageUpdateVO) {
        Tool toolManage = ToolManageConvert.INSTANCE.updateToConvert(toolManageUpdateVO);
        return Boolean.valueOf(updateById(toolManage));
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public IPage<ToolManageVO> pageTool(ToolQueryVO toolQueryVO, Query query) {
        return ((ToolManageMapper) this.baseMapper).page(Condition.getPage(query), toolQueryVO);
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public Boolean removeTool(List<Long> ids) {
        List<Tool> toolManageList = list(Lambda.in((v0) -> {
            return v0.getId();
        }, ids));
        Set<Integer> toolUseStateSet = (Set) toolManageList.stream().map((v0) -> {
            return v0.getUseState();
        }).collect(Collectors.toSet());
        if (toolUseStateSet.contains(ToolUseStateEnum.EQUIP.getCode())) {
            throw new ServiceException(MessageUtils.message("tool.tool.of.equip.dont.remove", new Object[0]));
        }
        return Boolean.valueOf(remove(Lambda.in((v0) -> {
            return v0.getId();
        }, ids)));
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    @Transactional(rollbackFor = {Exception.class})
    public List<ToolManageVO> dischargeTool(ToolDischargeVO toolDischargeVO) {
        List<Tool> toolList = list(Lambda.in(Tool::getId, toolDischargeVO.getIds()).eq(Tool::getUseState, ToolUseStateEnum.DISCHARGE.getCode()));
        /*
        List<Tool> toolList = list((Wrapper) Lambda.in((v0) -> {
            return v0.getId();
        }, toolDischargeVO.getIds()).eq((v0) -> {
            return v0.getUseState();
        }, ToolUseStateEnum.DISCHARGE.getCode()));*/
        if (Func.isNotEmpty(toolList)) {
            throw new ServiceException(MessageUtils.message("tool.tool.is.already.discharge", new Object[0]));
        }
        List<Tool> toolManageList = listByIds(toolDischargeVO.getIds());
        toolManageList.forEach(item -> {
            item.setUseState(ToolUseStateEnum.DISCHARGE.getCode());
        });
        this.toolChangeRecordService.dischargeToolChangeRecord(toolManageList, toolDischargeVO.getEmployeeId());
        update(Wrappers.<Tool>lambdaUpdate().in(Tool::getId, toolDischargeVO.getIds())
                .set(Tool::getWorkstationId, null)
                .set(Tool::getWorkstationCode, null)
                .set(Tool::getWorkstationName, null)
                .set(Tool::getToolPosition, null)
                .set(Tool::getUseState, ToolUseStateEnum.DISCHARGE.getCode()));
        /*
        update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().in((v0) -> {
            return v0.getId();
        }, toolDischargeVO.getIds())).set((v0) -> {
            return v0.getWorkstationId();
        }, (Object) null)).set((v0) -> {
            return v0.getWorkstationCode();
        }, (Object) null)).set((v0) -> {
            return v0.getWorkstationName();
        }, (Object) null)).set((v0) -> {
            return v0.getToolPosition();
        }, (Object) null)).set((v0) -> {
            return v0.getUseState();
        }, ToolUseStateEnum.DISCHARGE.getCode()));*/
        return ToolManageConvert.INSTANCE.convert(toolManageList);
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    @Transactional(rollbackFor = {Exception.class})
    public ToolManageVO equipmentTool(ToolManageEquipmentVO toolManageEquipmentVO) {
        
        Tool tool = getOne(Lambda.eq(Tool::getWorkstationId, toolManageEquipmentVO.getWorkstationId()).eq(Tool::getToolPosition, toolManageEquipmentVO.getToolPosition()));
        
        if (Func.isNotEmpty(tool)) {
            throw new ServiceException(MessageUtils.message("tool.tool.position.exist.tool", new Object[0]));
        }
        Workstation workstation = (Workstation) this.workstationService.getById(toolManageEquipmentVO.getWorkstationId());
        update(Wrappers.<Tool>lambdaUpdate()
                .eq(Tool::getId, toolManageEquipmentVO.getId())
                .set(Tool::getWorkstationId, workstation.getId())
                .set(Tool::getWorkstationName, workstation.getName())
                .set(Tool::getWorkstationCode, workstation.getCode())
                .set(Tool::getToolPosition, toolManageEquipmentVO.getToolPosition())
                .set(Tool::getUseState, ToolUseStateEnum.EQUIP.getCode()));
        /*
        update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
            return v0.getId();
        }, toolManageEquipmentVO.getId())).set((v0) -> {
            return v0.getWorkstationId();
        }, workstation.getId())).set((v0) -> {
            return v0.getWorkstationName();
        }, workstation.getName())).set((v0) -> {
            return v0.getWorkstationCode();
        }, workstation.getCode())).set((v0) -> {
            return v0.getToolPosition();
        }, toolManageEquipmentVO.getToolPosition())).set((v0) -> {
            return v0.getUseState();
        }, ToolUseStateEnum.EQUIP.getCode()));
        */
        Tool toolManage = (Tool) getById(toolManageEquipmentVO.getId());
        this.toolChangeRecordService.equipmentToolChangeRecord(toolManage, toolManageEquipmentVO.getEmployeeId());
        return ToolManageConvert.INSTANCE.convert(toolManage);
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean resetTool(Long id) {
        Tool toolManage = (Tool) getById(id);
        toolManage.setUsedLife(0);
        toolManage.setRemainLife(toolManage.getInitialLife());
        boolean flag = update(Wrappers.<Tool>lambdaUpdate()
                .eq(Tool::getId, id)
                .set(Tool::getUsedLife, 0)
                .set(Tool::getRemainLife, toolManage.getInitialLife())
                .set(Tool::getToolPosition, null)
                .set(Tool::getLifeState, ToolLifeStateEnum.NORMAL.getCode()));
        /*
        boolean flag = update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
            return v0.getId();
        }, id)).set((v0) -> {
            return v0.getUsedLife();
        }, 0)).set((v0) -> {
            return v0.getRemainLife();
        }, toolManage.getInitialLife())).set((v0) -> {
            return v0.getToolPosition();
        }, (Object) null)).set((v0) -> {
            return v0.getLifeState();
        }, ToolLifeStateEnum.NORMAL.getCode()));
        */
        if (Func.isEmpty(toolManage.getWorkstationId())) {
            return Boolean.valueOf(flag);
        }
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        Employee employee = (Employee) this.employeeService.getOne(Lambda.eq((v0) -> {
            return v0.getUserId();
        }, AuthUtil.getUserId()));
        if (Func.isEmpty(employee)) {
            throw new ServiceException(MessageUtils.message("sys.outer.user.not.bind.employee", new Object[0]));
        }
        dischargeTool(new ToolDischargeVO(ids, employee.getId()));
        return true;
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public BladeFile exportToolManage(ToolQueryVO toolQueryVO) throws Exception {
        List<ToolManageVO> toolManageVOList = pageTool(toolQueryVO, new Query().setSize(-1)).getRecords();
        List<Tool> toolManageList = ToolManageConvert.INSTANCE.convertVO(toolManageVOList);
        List<ToolManageExcel> toolManageExcels = new ArrayList<>();
        for (int i = 0; i < toolManageList.size(); i++) {
            ToolManageExcel toolManageExcel = ToolManageConvert.INSTANCE.convertToExcel(toolManageList.get(i));
            toolManageExcel.setUseState(Func.isNotEmpty(toolManageList.get(i).getUseState()) ? ToolUseStateEnum.findByCode(toolManageList.get(i).getUseState()).getDesc() : null);
            toolManageExcel.setLifeCountMethod(Func.isNotEmpty(toolManageList.get(i).getLifeCountMethod()) ? ToolLifeCountMethodEnum.findByCode(toolManageList.get(i).getLifeCountMethod()).getDesc() : null);
            toolManageExcel.setLifeState(Func.isNotEmpty(toolManageList.get(i).getLifeState()) ? ToolLifeStateEnum.findByCode(toolManageList.get(i).getLifeState()).getDesc() : null);
            toolManageExcels.add(toolManageExcel);
        }
        String fileName = String.format("%s-%s.xlsx", "刀具监控", DateUtil.time());
        MultipartFile multipartFile = toolManageExcelExport(fileName, TOOL_EXCEL_NAME, toolManageExcels, toolManageList, ToolManageExcel.class);
        return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public Boolean isExistCodeRule(String ruleFieldDictKey) {
        return Boolean.valueOf((this.basCoderuleService.count(Wrappers.<BasCodeRule>lambdaQuery().eq(BasCodeRule::getRuleFieldDictKey, ruleFieldDictKey)) > 0L));
         /*
        return Boolean.valueOf(this.basCoderuleService.count((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getRuleFieldDictKey();
        }, ruleFieldDictKey)) > 0);*/
    }
 
    @Override // org.springblade.modules.tool.service.IToolManageService
    public List<ToolManageTreeVO> tree() {
        List<ToolManageTreeVO> list = Lists.newArrayList();
        List<ToolCategory> toolCategoryList = this.toolCategoryService.list();
        toolCategoryList.forEach(x -> {
            ToolManageTreeVO toolManageTreeVO = ToolManageConvert.INSTANCE.convert(x);
            toolManageTreeVO.setIsGroup(Boolean.TRUE);
            list.add(toolManageTreeVO);
        });
        List<ToolModel> toolModelList = this.toolModelService.list();
        toolModelList.forEach(x2 -> {
            ToolManageTreeVO toolManageTreeVO = ToolManageConvert.INSTANCE.convert(x2);
            toolManageTreeVO.setIsGroup(Boolean.TRUE);
            list.add(toolManageTreeVO);
        });
        List<ToolManageTreeVO> toolList = ((ToolManageMapper) this.baseMapper).getToolTreeList();
        list.addAll(toolList);
        return ForestNodeMerger.merge(list);
    }
 
    public MultipartFile toolManageExcelExport(String excelFileName, String sheetName, List<ToolManageExcel> toolManageExcels, List<Tool> toolManageList, Class<ToolManageExcel> clazz) throws Exception {
        String fileName = new String(excelFileName.getBytes(), StandardCharsets.UTF_8);
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        FileItem fileItem = factory.createItem("excel", "application/vnd.ms-excel", true, fileName);
        OutputStream os = fileItem.getOutputStream();
        WriteCellStyle contentWriteCellStyleWarn = new WriteCellStyle();
        contentWriteCellStyleWarn.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        contentWriteCellStyleWarn.setFillForegroundColor(Short.valueOf(IndexedColors.YELLOW.getIndex()));
        WriteCellStyle contentWriteCellStyleNormal = new WriteCellStyle();
        WriteCellStyle contentWriteCellStyleCallThePolice = new WriteCellStyle();
        contentWriteCellStyleCallThePolice.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        contentWriteCellStyleCallThePolice.setFillForegroundColor(Short.valueOf(IndexedColors.RED.getIndex()));
        List<WriteCellStyle> preList = new ArrayList<>();
        toolManageExcels.forEach(toolManageExcel -> {
            if (Objects.equals(toolManageExcel.getLifeState(), ToolLifeStateEnum.WARN.getDesc())) {
                preList.add(contentWriteCellStyleWarn);
            } else if (Objects.equals(toolManageExcel.getLifeState(), ToolLifeStateEnum.CALL_THE_POLICE.getDesc())) {
                preList.add(contentWriteCellStyleCallThePolice);
            } else {
                preList.add(contentWriteCellStyleNormal);
            }
        });
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, preList);
        EasyExcel.write(os).head(getHead()).registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new CustomCellWriteHandler()).sheet(sheetName).doWrite(getData(toolManageList));
        return new CommonsMultipartFile(fileItem);
    }
 
    public List<List<String>> getHead() {
        List<List<String>> list = new ArrayList<>();
        ToolManageExcel toolManageExcel = new ToolManageExcel();
        Field[] fields = toolManageExcel.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            ExcelProperty annotation = field.getAnnotation(ExcelProperty.class);
            if (Func.isNotEmpty(annotation)) {
                List<String> head = new ArrayList<>(3);
                head.add(annotation.value()[0]);
                head.add(annotation.value()[1]);
                head.add(annotation.value()[2]);
                list.add(head);
            }
        }
        List<ToolParameter> toolParameterList = this.toolParameterService.list(Wrappers.<ToolParameter>lambdaQuery().orderByAsc(ToolParameter::getToolParameterCode));
        /*
        List<ToolParameter> toolParameterList = this.toolParameterService.list((Wrapper) Wrappers.lambdaQuery().orderByAsc((v0) -> {
            return v0.getToolParameterCode();
        }));*/
        List<String> toolParameterNameList = toolParameterList.stream().map((v0) -> {
            return v0.getToolParameterName();
        }).collect(Collectors.toList());
        Map<String, String> nameUnitMap = toolParameterList.stream().filter(item -> {
            return Func.isNotEmpty(item.getToolParameterUnit());
        }).collect(Collectors.toMap((v0) -> {
            return v0.getToolParameterName();
        }, (v0) -> {
            return v0.getToolParameterUnit();
        }));
        for (String name : toolParameterNameList) {
            List<String> head2 = new ArrayList<>();
            head2.add(TOOL_EXCEL_NAME);
            head2.add("");
            head2.add(nameUnitMap.containsKey(name) ? name + "(" + nameUnitMap.get(name) + ")" : name);
            list.add(head2);
        }
        return list;
    }
 
    public List<List<Object>> getData(List<Tool> toolManageList) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException {
        Class<?> cls = Class.forName("com.qianwen.smartman.modules.tool.excel.ToolManageExcel");
        Field liftState = cls.getDeclaredField("lifeState");
        List<String> toolParameterCodeList = this.toolParameterService.list(Wrappers.<ToolParameter>lambdaQuery().orderByAsc(ToolParameter::getToolParameterCode)).stream().map(ToolParameter::getToolParameterCode).collect(Collectors.toList());
        /*
        List<String> toolParameterCodeList = (List) this.toolParameterService.list((Wrapper) Wrappers.lambdaQuery().orderByAsc((v0) -> {
            return v0.getToolParameterCode();
        })).stream().map((v0) -> {
            return v0.getToolParameterCode();
        }).collect(Collectors.toList());
        */
        List<List<Object>> list = new ArrayList<>();
        for (Tool tool : toolManageList) {
            ToolManageExcel toolManageExcel = ToolManageConvert.INSTANCE.convertToExcel(tool);
            toolManageExcel.setUseState(Func.isNotEmpty(toolManageExcel.getUseState()) ? ToolUseStateEnum.findByCode(Integer.valueOf(toolManageExcel.getUseState())).getDesc() : null);
            toolManageExcel.setLifeCountMethod(Func.isNotEmpty(toolManageExcel.getLifeCountMethod()) ? ToolLifeCountMethodEnum.findByCode(Integer.valueOf(toolManageExcel.getLifeCountMethod())).getDesc() : null);
            toolManageExcel.setInitialLife(toolManageExcel.getInitialLife() + "次");
            toolManageExcel.setUsedLife(toolManageExcel.getUsedLife() == null ? "0" : toolManageExcel.getUsedLife() + "次");
            toolManageExcel.setRemainLife(toolManageExcel.getRemainLife() + "次");
            List<Object> objectList = new ArrayList<>();
            List<Field> fieldList = Arrays.stream(toolManageExcel.getClass().getDeclaredFields()).filter(field -> {
                return !field.equals(liftState);
            }).collect(Collectors.toList());
            for (Field field2 : fieldList) {
                field2.setAccessible(true);
                objectList.add(field2.get(toolManageExcel));
            }
            for (String code : toolParameterCodeList) {
                Field field3 = Tool.class.getDeclaredField(code);
                field3.setAccessible(true);
                Object codeValue = field3.get(tool);
                objectList.add(codeValue);
            }
            list.add(objectList);
        }
        return list;
    }
}