Lius
2025-04-23 a90ae030ad64da0e44f48f4b1bb044753c1acff2
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
package org.jeecg.modules.eam.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.FileUploadResult;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus;
import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum;
import org.jeecg.modules.eam.constant.EquipmentRepairStatus;
import org.jeecg.modules.eam.constant.ReportRepairEnum;
import org.jeecg.modules.eam.entity.EamInspectionOrderDetail;
import org.jeecg.modules.eam.entity.EamReportRepair;
import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrderDetail;
import org.jeecg.modules.eam.mapper.EamReportRepairMapper;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
import org.jeecg.modules.eam.service.IEamReportRepairService;
import org.springframework.beans.factory.annotation.Autowired;
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.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
/**
 * @Description: 故障报修
 * @Author: Lius
 * @Date: 2025-04-01
 */
@Service
public class EamReportRepairServiceImpl extends ServiceImpl<EamReportRepairMapper, EamReportRepair> implements IEamReportRepairService {
 
    @Resource
    private IEamEquipmentExtendService eamEquipmentExtendService;
 
    /**
     * 分页列表
     *
     * @param page
     * @param eamReportRepairQuery
     * @return
     */
    @Override
    public IPage<EamReportRepair> pageList(Page<EamReportRepair> page, EamReportRepairQuery eamReportRepairQuery) {
        //用户数据权限
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return page;
        }
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
            //选择了设备,根据设备id过滤设备
            equipmentIds = Arrays.asList(sysUser.getEquipmentIds().split(","));
        }
        return this.baseMapper.pageList(page, eamReportRepairQuery, sysUser.getId(), equipmentIds);
    }
 
    @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.setFaultName("周保执行报修处理");
        entity.setFaultDescription(sb.toString());
        entity.setFaultType(CommonConstant.DEFAULT_1);
        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        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.setFaultName("点检执行报修处理");
        entity.setFaultDescription(sb.toString());
        entity.setFaultType(CommonConstant.DEFAULT_1);
        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        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(EamReportRepair eamReportRepair) {
        eamReportRepair.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
        eamReportRepair.setDelFlag(CommonConstant.DEL_FLAG_0);
        // 附件处理
        if (eamReportRepair.getImageFilesResult() != null) {
            List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult();
            ObjectMapper mapper = new ObjectMapper();
            try {
                String referenceFile = mapper.writeValueAsString(imageFilesResult);
                eamReportRepair.setImageFiles(referenceFile);
            } catch (JsonProcessingException e) {
                return null;
            }
        }
        this.baseMapper.insert(eamReportRepair);
        //更新设备维修状态
        eamEquipmentExtendService.updateEquipmentRepairStatus(eamReportRepair.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
        return eamReportRepair;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean edit(EamReportRepair eamReportRepair) {
        // 附件处理
        if (eamReportRepair.getImageFilesResult() != null) {
            List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult();
            ObjectMapper mapper = new ObjectMapper();
            try {
                String referenceFile = mapper.writeValueAsString(imageFilesResult);
                eamReportRepair.setImageFiles(referenceFile);
            } catch (JsonProcessingException e) {
                return false;
            }
        } else {
            eamReportRepair.setImageFiles(null);
        }
        this.baseMapper.updateById(eamReportRepair);
        return true;
    }
}