whyclxw
2025-06-12 eb81b0a16b2d4e87eefd085231ab6b20a1ea3cde
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
package com.whyc.service;
 
import com.whyc.constant.BattSingalIdEnum;
import com.whyc.constant.DevAlarmEnum;
import com.whyc.constant.PowerAlarmEnum;
import com.whyc.dto.Response;
import com.whyc.mapper.AlarmInspectionMapper;
import com.whyc.pojo.db_user.Baojigroup;
import com.whyc.pojo.db_user.User;
import com.whyc.pojo.web_site.AlarmInspection;
import com.whyc.pojo.web_site.AlarmInspectionResult;
import com.whyc.util.CommonUtil;
import com.whyc.util.DateUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class AlarmInspectionService {
 
    @Resource
    private AlarmInspectionMapper mapper;
 
    @Autowired
    private AlarmInspectionResultService resultService;
 
    public Response getList(Integer stationId, Integer inspectionType) {
        //需要附加填充 负责班组信息 及 告警诊断信息
        List<AlarmInspection> list = mapper.getList(stationId,inspectionType);
        return new Response().set(1,list);
    }
 
    @Transactional
    public Response submitInspection(AlarmInspectionResult result, List<MultipartFile> file) throws IOException {
        //对file进行处理,保存到文件夹中
        //对存储路径进行定义
        String stationName = result.getStationName();
        Date now = new Date();
        String timeFormat = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM_DD_HH_MM_SS_UNION, now);
        String fileDirPath = CommonUtil.getRootFile() + "alarmInspection" + File.separator + stationName + "_" + timeFormat;
        File fileDir = new File(fileDirPath);
        //如果文件夹不存在则创建
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }
        StringBuilder pictureUrlSb = new StringBuilder();
        if (file != null && file.size() > 0) {
            for (MultipartFile multipartFile : file) {
                String fileName = multipartFile.getOriginalFilename();
                //将fileName中可能存在的,去掉
                fileName = fileName.replace(",","");
                String filePath = fileDirPath + File.separator + fileName;
 
                multipartFile.transferTo(new File(filePath));
                String split = "pis_file"+File.separator+"alarmInspection";
                pictureUrlSb.append(File.separator + filePath.substring(filePath.indexOf(split))).append(",");
            }
        }
        result.setPictureUrl(pictureUrlSb.toString());
 
        //根据提交的站点id和inspectionType查询出对应的工单
        List<AlarmInspection> list = mapper.getList(result.getStationId(),result.getInspectionType());
        //校验告警是否全部消失,是则通过
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getIsExist() == 1) {
                return new Response().set(1,false,"当前巡检单内告警未全部消失");
            }
        }
        //检验通过,进行巡检结果提交,形成巡检历史
        //判断stationName,powerName,devName,battGroupName是否存在,逐个存在则拼接成一个字符串
        StringBuilder alarmDescriptionSb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            AlarmInspection temp = list.get(i);
            if (temp.getStationName() != null) {
                alarmDescriptionSb.append(temp.getStationName()).append("-");
            }
            if (temp.getPowerName() != null) {
                alarmDescriptionSb.append(temp.getPowerName()).append("-");
            }
            if (temp.getDevName() != null) {
                alarmDescriptionSb.append(temp.getDevName()).append("-");
            }
            if (temp.getBattGroupName() != null) {
                alarmDescriptionSb.append(temp.getBattGroupName());
            }
            if(temp.getMonNum() != null){
                alarmDescriptionSb.append("单体编号:").append(temp.getMonNum());
            }
            if(temp.getType() == 1) { //电源告警
                alarmDescriptionSb.append("在" + DateUtil.YYYY_MM_DD_HH_MM_SS.format(temp.getAlmStartTime()) + "发生" + PowerAlarmEnum.getValue(temp.getAlmId()) + "告警,告警级别为" + temp.getAlmLevel() + ".\n");
            }
            else if(temp.getType() == 2) { //设备告警
                alarmDescriptionSb.append("在" + DateUtil.YYYY_MM_DD_HH_MM_SS.format(temp.getAlmStartTime()) + "发生" + DevAlarmEnum.getValue(temp.getAlmId()) + "告警,告警级别为" + temp.getAlmLevel() + ".\n");
            }else{ //电池告警
                alarmDescriptionSb.append("在" + DateUtil.YYYY_MM_DD_HH_MM_SS.format(temp.getAlmStartTime()) + "发生" + BattSingalIdEnum.getValue(temp.getAlmId()) +"告警,告警级别为" + temp.getAlmLevel() + ".\n");
            }
        }
        result.setAlarmDescription(alarmDescriptionSb.toString());
        User user = CommonUtil.getUser();
        result.setSubmitUserId(user.getId());
        result.setSubmitUserName(user.getName());
        result.setCreateTime(new Date());
        //所属班组
        Baojigroup baoJiGroup = list.get(0).getBaoJiGroup();
        result.setBaoJiGroupId(baoJiGroup.getBaojiGroupId());
        result.setBaoJiGroupName(baoJiGroup.getBaojiGroupName());
        resultService.add(result);
 
        //删除当前巡检单记录
        List<Long> ids = list.stream().map(AlarmInspection::getId).collect(Collectors.toList());
        mapper.deleteBatchIds(ids);
 
        return new Response().set(1,true,"提交完成");
    }
}