lyh
23 小时以前 582bb2627712f66157b5608c8f5798775fc38266
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 org.jeecg.modules.eam.service.impl;
 
import cn.hutool.core.util.StrUtil;
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.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.*;
import org.jeecg.modules.eam.dto.EamRepairOrderDto;
import org.jeecg.modules.eam.dto.EamReportRepairDto;
import org.jeecg.modules.eam.dto.EchartsDto;
import org.jeecg.modules.eam.entity.*;
import org.jeecg.modules.eam.mapper.EamReportRepairMapper;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.request.EamReportRepairRequest;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.entity.SysAnnouncementSend;
import org.jeecg.modules.system.service.IBaseFactoryService;
import org.jeecg.modules.system.service.IBaseFactoryUserService;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description: 故障报修
 * @Author: Lius
 * @Date: 2025-04-01
 */
@Service
public class EamReportRepairServiceImpl extends ServiceImpl<EamReportRepairMapper, EamReportRepair> implements IEamReportRepairService {
 
    @Resource
    private IEamEquipmentExtendService eamEquipmentExtendService;
 
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    private IEamReportProductHazardsService iEamReportProductHazardsService;
    @Autowired
    private IEamReportAccidentsRegisterService iEamReportAccidentsRegisterService;
    @Autowired
    @Lazy
    private IEamRepairOrderService iEamRepairOrderService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
    @Autowired
    private IEamReportThreeNoSpareService eamReportThreeNoSpareService;
    @Autowired
    private IEamBaseHFCodeService hfCodeService;
    /**
     * 分页列表
     *
     * @param page
     * @param query
     * @return
     */
    @Override
    public IPage<EamReportRepairDto> pageList(Page<EamReportRepairDto> page, EamReportRepairQuery query) {
        QueryWrapper<EamReportRepairDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0);
        //用户数据权限
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return page;
        }
        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
            //选择了设备,根据设备id过滤设备
            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
            queryWrapper.in("e.equipment_code", equipArr);
        } else {
            //没有选择设备,根据中心过滤设备
            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
            if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
                Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCode);
            } else {
                return page;
            }
        }
        //查询条件过滤
        if (query != null) {
            if (StringUtils.isNotBlank(query.getEquipmentId())) {
                queryWrapper.eq("wmo.equipment_id", query.getEquipmentId());
            }
            if (StringUtils.isNotBlank(query.getEquipmentCode())) {
                queryWrapper.like("e.equipment_code", query.getEquipmentCode());
            }
            if (StringUtils.isNotBlank(query.getEquipmentName())) {
                queryWrapper.like("e.equipment_name", query.getEquipmentName());
            }
            if (StringUtils.isNotBlank(query.getBreakdownFlag())) {
                queryWrapper.eq("wmo.breakdown_flag", query.getBreakdownFlag());
            }
            if (StringUtils.isNotBlank(query.getReportStatus())) {
                queryWrapper.eq("wmo.report_status", query.getReportStatus());
            }
            if (StringUtils.isNotBlank(query.getFaultDescription())) {
                queryWrapper.like("wmo.fault_description", query.getFaultDescription());
            }
            if(query.getStartTime() != null && query.getEndTime() != null) {
                queryWrapper.between("wmo.fault_start_time", query.getStartTime(), query.getEndTime());
            }
            //排序
            if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) {
                String column = query.getColumn();
                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
                }
                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) {
                    queryWrapper.orderByAsc("wmo." + oConvertUtils.camelToUnderline(column));
                } else {
                    queryWrapper.orderByDesc("wmo." + oConvertUtils.camelToUnderline(column));
                }
            } else {
                queryWrapper.orderByDesc("wmo.create_time");
            }
        } else {
            queryWrapper.orderByDesc("wmo.create_time");
        }
 
        return baseMapper.queryPageList(page, queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
    public EamReportRepair reportRepairFromMaintenance(String equipmentId, String reportUser, List<EamWeekMaintenanceOrderDetail> detailList) {
        StringBuilder sb = new StringBuilder();
        detailList.forEach(detail -> {
            sb.append(detail.getItemCode()).append("、");
            sb.append(detail.getExceptionDescription()).append(";");
        });
        EamReportRepair entity = new EamReportRepair();
        entity.setEquipmentId(equipmentId);
        entity.setCreateBy(reportUser);
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultDescription(sb.toString());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return entity;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
    public EamReportRepair reportRepairFromInspection(String equipmentId, String reportUser, List<EamInspectionOrderDetail> detailList) {
        StringBuilder sb = new StringBuilder();
        detailList.forEach(detail -> {
            sb.append(detail.getItemCode()).append("、");
            sb.append(detail.getExceptionDescription()).append(";");
        });
        EamReportRepair entity = new EamReportRepair();
        entity.setEquipmentId(equipmentId);
        entity.setCreateBy(reportUser);
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultDescription(sb.toString());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return entity;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
    public EamReportRepair add(EamReportRepairRequest eamReportRepairRequest) {
        EamReportRepair eamReportRepair = new EamReportRepair();
        BeanUtils.copyProperties(eamReportRepairRequest, eamReportRepair);
        eamReportRepair.setDelFlag(CommonConstant.DEL_FLAG_0);
        eamReportRepair.setReportStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name());
        this.baseMapper.insert(eamReportRepair);
        if(StrUtil.isNotEmpty(eamReportRepair.getIsProcessed())&&("1").equals(eamReportRepair.getIsProcessed())){
            //添加产品安全隐患确认
            EamReportProductHazards eamReportProductHazards=new EamReportProductHazards();
            eamReportProductHazards.setEquipmentId(eamReportRepair.getEquipmentId());
            eamReportProductHazards.setReportId(eamReportRepair.getId());
            eamReportProductHazards.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.PENDING_SUBMIT.name());
            EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_PRODUCT_HAZARDS.name());
            if (eamBaseHFCode == null) {
                throw new JeecgBootException("未配置产品安全隐患确认的HF编码,添加失败!");
            }
            eamReportProductHazards.setHfCode(eamBaseHFCode.getHfCode());
            iEamReportProductHazardsService.save(eamReportProductHazards);
        }
        if (StrUtil.isNotEmpty(eamReportRepair.getIsAccidentsRegister())&&("1").equals(eamReportRepair.getIsAccidentsRegister())) {
            //添加设备事故登记表
            EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister();
            BeanUtils.copyProperties(eamReportRepairRequest, eamReportAccidentsRegister);
            eamReportAccidentsRegister.setId(null);
            eamReportAccidentsRegister.setReportId(eamReportRepair.getId());
            eamReportAccidentsRegister.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            eamReportAccidentsRegister.setRegisterStatus(EamReportAccidentsRegisterEnum.PENDING_SUBMIT.name());
            EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_ACCIDENTS_REGISTER.name());
            if (eamBaseHFCode == null) {
                throw new JeecgBootException("未配置设备事故登记表的HF编码,添加失败!");
            }
            eamReportAccidentsRegister.setHfCode(eamBaseHFCode.getHfCode());
            iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister);
            //生成三不原则
            EamReportThreeNoSpare eamReportThreeNoSpare = new EamReportThreeNoSpare();
            BeanUtils.copyProperties(eamReportRepairRequest, eamReportThreeNoSpare);
            eamReportThreeNoSpare.setId(null);
            eamReportThreeNoSpare.setReportId(eamReportRepair.getId());
            eamReportThreeNoSpare.setPreventionMeasures(eamReportAccidentsRegister.getTakeSteps());
            eamReportThreeNoSpare.setSubmitStatus(EamReportThreeNoSpareEnum.PENDING_SUBMIT.name());
            eamReportThreeNoSpare.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            EamBaseHFCode threeHfCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_THREE_NO_SPARE.name());
            if (threeHfCode == null) {
                throw new JeecgBootException("未配置三不放过原则表的HF编码,添加失败!");
            }
            eamReportThreeNoSpare.setHfCode(threeHfCode.getHfCode());
            eamReportThreeNoSpareService.save(eamReportThreeNoSpare);
        }
        //生成维修工单
        EamRepairOrder eamRepairOrder=new EamRepairOrder();
        BeanUtils.copyProperties(eamReportRepairRequest, eamRepairOrder);
        String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.REPAIR_ORDER_CODE_RULE);
        eamRepairOrder.setRepairCode(codeSeq);
        eamRepairOrder.setId(null);
        eamRepairOrder.setDelFlag(CommonConstant.DEL_FLAG_0);
        eamRepairOrder.setReportId(eamReportRepair.getId());
        eamRepairOrder.setReportPerson(eamReportRepair.getCreateBy());
        eamRepairOrder.setFaultPhenomenon(eamReportRepair.getFaultDescription());
        eamRepairOrder.setFaultStartTime(eamReportRepair.getFaultStartTime());
        eamRepairOrder.setClaimStatus("0");
        eamRepairOrder.setRepairStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name());
        iEamRepairOrderService.save(eamRepairOrder);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(eamReportRepair.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return eamReportRepair;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean edit(EamReportRepairDto eamReportRepairDto) {
        LambdaUpdateWrapper<EamReportRepair> updateWrapper = new UpdateWrapper().lambda();
        EamReportRepair eamReportRepair=new EamReportRepair();
        BeanUtils.copyProperties(eamReportRepairDto, eamReportRepair);
        if(StrUtil.isNotEmpty(eamReportRepairDto.getIsProcessed())){
            //todo 缺少对应流程判断
            if ("0".equals(eamReportRepairDto.getIsProcessed())) {
                updateWrapper.set(EamReportRepair::getBatchNumber,null);
                updateWrapper.set(EamReportRepair::getProcessingPart,null);
                updateWrapper.set(EamReportRepair::getQuantity, null);
            }
            //直接删除再添加
            iEamReportProductHazardsService.remove(new QueryWrapper<EamReportProductHazards>().eq("report_id",eamReportRepairDto.getId())
                    .eq("equipment_id",eamReportRepairDto.getEquipmentId()));
            //添加产品安全隐患确认
            EamReportProductHazards eamReportProductHazards=new EamReportProductHazards();
            eamReportProductHazards.setEquipmentId(eamReportRepairDto.getEquipmentId());
            eamReportProductHazards.setReportId(eamReportRepairDto.getId());
            eamReportProductHazards.setId(null);
            iEamReportProductHazardsService.save(eamReportProductHazards);
        }
        if (StrUtil.isNotEmpty(eamReportRepairDto.getIsAccidentsRegister())) {
            //todo 缺少对应流程判断
            if ("0".equals(eamReportRepairDto.getIsAccidentsRegister())) {
                updateWrapper.set(EamReportRepair::getScrapPartNumber,null);
                updateWrapper.set(EamReportRepair::getScrapPartValue, null);
                updateWrapper.set(EamReportRepair::getScrapPartQuantity, null);
            }
            //直接删除再添加
            iEamReportAccidentsRegisterService.remove(new QueryWrapper<EamReportAccidentsRegister>()
                    .eq("report_id",eamReportRepairDto.getId()).eq("equipment_id",eamReportRepairDto.getEquipmentId()));
            //添加设备事故登记表
            EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister();
            BeanUtils.copyProperties(eamReportRepairDto, eamReportAccidentsRegister);
            eamReportAccidentsRegister.setReportId(eamReportRepairDto.getId());
            eamReportAccidentsRegister.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0));
            eamReportAccidentsRegister.setId(null);
            iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister);
        }
        updateWrapper.eq(EamReportRepair::getId,eamReportRepairDto.getId());
        this.update(eamReportRepair,updateWrapper);
        //修改维修工单
        EamRepairOrder eamRepairOrder=iEamRepairOrderService.
                getOne(new QueryWrapper<EamRepairOrder>().eq("report_id",eamReportRepairDto.getId()));
        eamRepairOrder.setFaultStartTime(eamReportRepairDto.getFaultStartTime());
        eamRepairOrder.setFaultPhenomenon(eamReportRepairDto.getFaultDescription());
        iEamRepairOrderService.updateById(eamRepairOrder);
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
    public EamReportRepair reportRepairFromSecondMaintenance(String equipmentId, String reportUser, List<EamSecondMaintenanceOrderDetail> detailList) {
        StringBuilder sb = new StringBuilder();
        detailList.forEach(detail -> {
            sb.append(detail.getItemCode()).append("、");
            sb.append(detail.getExceptionDescription()).append(";");
        });
        EamReportRepair entity = new EamReportRepair();
        entity.setEquipmentId(equipmentId);
        entity.setCreateBy(reportUser);
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultDescription(sb.toString());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return entity;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
    public EamReportRepair reportRepairFromThirdMaintenance(String equipmentId, String reportUser, List<EamThirdMaintenanceOrderDetail> detailList) {
        StringBuilder sb = new StringBuilder();
        detailList.forEach(detail -> {
            sb.append(detail.getItemCode()).append("、");
            sb.append(detail.getExceptionDescription()).append(";");
        });
        EamReportRepair entity = new EamReportRepair();
        entity.setEquipmentId(equipmentId);
        entity.setCreateBy(reportUser);
        entity.setFaultStartTime(new Date());
        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
        entity.setFaultDescription(sb.toString());
        this.baseMapper.insert(entity);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return entity;
    }
 
    public List<EchartsDto> reportRepairList() {
        List<EchartsDto> echartsDtoList = new ArrayList<>();
 
        // 用户数据权限检查
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return echartsDtoList; // 返回空列表而非null
        }
 
        QueryWrapper<EamReportRepairDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0);
 
        // 设备过滤逻辑
        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
            queryWrapper.in("e.equipment_code", equipArr);
        } else {
            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService
                    .list(new LambdaQueryWrapper<BaseFactoryUser>()
                            .eq(BaseFactoryUser::getUserId, sysUser.getId()));
 
            if (CollectionUtils.isEmpty(baseFactoryUserList)) {
                return echartsDtoList; // 返回空列表而非null
            }
 
            Set<String> factoryIds = baseFactoryUserList.stream()
                    .map(BaseFactoryUser::getFactoryId)
                    .collect(Collectors.toSet());
 
            Set<String> factoryCodes = baseFactoryService.listByIds(factoryIds)
                    .stream()
                    .map(BaseFactory::getOrgCode)
                    .collect(Collectors.toSet());
 
            queryWrapper.in("e.factory_org_code", factoryCodes);
        }
 
        // 获取基础数据
        List<EamReportRepairDto> baseList = this.baseMapper.queryList(queryWrapper);
        int totalCount = baseList.size();
 
        // 获取停机数量
        int shutdownCount = this.baseMapper.queryList(
                queryWrapper.clone().eq("breakdown_flag", "1")
        ).size();
 
        // 计算运行数量
        int runningCount = totalCount - shutdownCount;
 
        // 处理零值情况
        if (totalCount == 0) {
            // 添加所有零值数据项
            addZeroValueData(echartsDtoList, "报修总数", "bx");
            addZeroValueData(echartsDtoList, "停机总数", "stop");
            addZeroValueData(echartsDtoList, "运行总数", "run");
            return echartsDtoList;
        }
 
        // 计算百分比
        BigDecimal total = new BigDecimal(totalCount);
        String bxPercentage = calculatePercentage(totalCount, BigDecimal.valueOf(totalCount));
        String stopPercentage = calculatePercentage(shutdownCount, BigDecimal.valueOf(totalCount));
        String runPercentage = calculatePercentage(runningCount, BigDecimal.valueOf(totalCount));
 
        // 构建返回数据
        echartsDtoList.add(createEchartsDto("报修总数", "bx", totalCount, bxPercentage));
        echartsDtoList.add(createEchartsDto("停机总数", "stop", shutdownCount, stopPercentage));
        echartsDtoList.add(createEchartsDto("运行总数", "run", runningCount, runPercentage));
 
        return echartsDtoList;
    }
 
    // 辅助方法:添加零值数据
    private void addZeroValueData(List<EchartsDto> list, String name, String code) {
        EchartsDto dto = new EchartsDto();
        dto.setName(name);
        dto.setCode(code);
        dto.setValue("0");
        dto.setPercentage("0.00%");
        list.add(dto);
    }
 
    // 辅助方法:计算百分比
    private String calculatePercentage(int value, BigDecimal total) {
        return new BigDecimal(value)
                .multiply(new BigDecimal(100))
                .divide(total, 2, RoundingMode.HALF_UP) + "%";
    }
 
    // 辅助方法:创建EchartsDto对象
    private EchartsDto createEchartsDto(String name, String code, int value, String percentage) {
        EchartsDto dto = new EchartsDto();
        dto.setName(name);
        dto.setCode(code);
        dto.setValue(String.valueOf(value));
        dto.setPercentage(percentage);
        return dto;
    }
}