fg电池监控平台的达梦数据库版本
whycxzp
2024-11-12 92ba7a968c67e8c8a64efea1759929649189f390
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.constant.YamlProperties;
import com.whyc.dto.AlarmDaoFactory;
import com.whyc.dto.Response;
import com.whyc.mapper.AlarmManualClearMapper;
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.DateUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
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.ArrayList;
import java.util.Date;
import java.util.List;
 
import static com.whyc.util.ActionUtil.createFilefolderIFNotExist;
 
@Service
public class AlarmManualClearService {
 
    @Resource
    private AlarmManualClearMapper mapper;
 
    @Autowired
    private BattInfService battInfService;
 
    @Autowired
    private PowerInfService powerInfService;
 
    @Autowired
    private BattAlarmDataVerifyService battAlarmService;
 
    @Autowired
    private BattalarmDataHistoryService battAlarmHistoryService;
 
    @Autowired
    private DevAlarmDataVerifyService devAlarmService;
 
    @Autowired
    private DevalarmDataHistoryService devAlarmHistoryService;
 
    @Autowired
    private PwrDevAlarmVerifyService powerAlarmService;
 
    @Autowired
    private PwrdevAlarmHistoryService powerAlarmHistoryService;
 
    @Transactional
    public Response submit(List<MultipartFile> file, AlarmManualClear clear) {
        int userId = ActionUtil.getUser().getUId().intValue();
        clear.setDealUserId(userId);
        Date date = new Date();
        clear.setCreateTime(date);
        //插入对应的站点id,用于后期用户相关
        Integer alarmType = clear.getAlarmType();
        Integer num = clear.getNum();
        if(alarmType == 1){ //电池告警
            //添加到历史告警,移除告警确认数据
            BattAlarmDataVerify data = battAlarmService.getById(num);
            battAlarmHistoryService.add(data);
            battAlarmService.delete(num);
        } else if (alarmType == 2) { //设备告警
            DevAlarmDataVerify data = devAlarmService.getById(num);
            devAlarmHistoryService.add(data);
            devAlarmService.delete(num);
 
        }else{ //电源告警
            PwrDevAlarmVerify data = powerAlarmService.getById(num);
            powerAlarmHistoryService.add(data);
            powerAlarmService.delete(num);
        }
        //处理文件
        String fileDirName = "";
        ApplicationHome applicationHome = new ApplicationHome(getClass());
        File jarFile = applicationHome.getDir();
        //测试版
        if (YamlProperties.runModel == 1) {
            fileDirName = jarFile.getParentFile().toString();
        } else {
            //打包版
            fileDirName = jarFile.toString();
        }
        //文件夹按月度存储
        //String root=fileDirName+"/fg_file/alarm_manual_clear/"+ DateUtil.YYYY_MM.format(date) + "/";
        String root=fileDirName+"/fg_file/alarm_manual_clear/"+ ThreadLocalUtil.format(date,5) + "/";
        List<String> filePathList = new ArrayList<>();
        try {
            for (int i = 0; i < file.size(); i++) {
                String fileFileName = file.get(i).getOriginalFilename();
                //String filePath = root + DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date)+"_"+fileFileName;
                String filePath = root + ThreadLocalUtil.format(date,7)+"_"+fileFileName;
                createFilefolderIFNotExist(filePath);
                file.get(i).transferTo(new File(filePath));
                String httpFilePath = filePath.replace(fileDirName, "");
                filePathList.add(httpFilePath);
            }
            StringBuilder filePathUnion = new StringBuilder();
            int size = filePathList.size();
            for (int i = 0; i < size; i++) {
                String filePath = filePathList.get(i);
                filePathUnion.append(filePath);
                if(i!= size -1) {
                    filePathUnion.append(";");
                }
            }
            clear.setFileUrl(filePathUnion.toString());
            mapper.insert(clear);
            return new Response().set(1,"提交完成");
        } catch (IOException e) {
            return new Response().set(0,"接口发生异常:"+e.toString());
        }
    }
 
    public Response getRecordByAlarmInfo(AlarmManualClear clear) {
        QueryWrapper<AlarmManualClear> query = Wrappers.query();
        Integer alarmType = clear.getAlarmType();
        String alarmName;
        if(alarmType == 1) {
            alarmName = AlarmDaoFactory.getAllAlarmName(clear.getAlmSignalId());
            query.eq("batt_group_id",clear.getBattGroupId()).eq("alm_signal_id",clear.getAlmSignalId());
        }else if(alarmType == 2){
            query.eq("device_id",clear.getDeviceId());
            alarmName = AlarmDaoFactory.getAllAlarmName(clear.getAlmId());
        }else{
            query.eq("power_device_id",clear.getPowerDeviceId());
            alarmName = AlarmDaoFactory.getAllAlarmName(clear.getAlmId());
        }
        query.eq("alm_start_time",clear.getAlmStartTime())
                .eq("alm_id",clear.getAlmId()).last(" limit 1");
        AlarmManualClear clearDB = mapper.selectOne(query);
 
        clearDB.setAlarmName(alarmName);
        return new Response().set(1,clearDB);
 
    }
 
    public Response getPage(AlarmManualClear param) {
        int userId = ActionUtil.getUser().getUId().intValue();
        //查询所有的记录分页
        param.setDealUserId(userId);
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        List<AlarmManualClear> list = mapper.getAll(param);
        PageInfo<AlarmManualClear> pageInfo = new PageInfo<>(list);
        ////装配电池/设备/电源信息
        //List<AlarmManualClear> dataList = pageInfo.getList();
        //List<Integer> battGroupIdList = dataList.stream().filter(data -> data.getAlarmType() == 1).map(AlarmManualClear::getBattGroupId).collect(Collectors.toList());
        //List<Integer> deviceIdList = dataList.stream().filter(data -> data.getAlarmType() == 2).map(AlarmManualClear::getDeviceId).collect(Collectors.toList());
        //List<Integer> powerDeviceIdList = dataList.stream().filter(data -> data.getAlarmType() == 3).map(AlarmManualClear::getPowerDeviceId).collect(Collectors.toList());
        pageInfo.getList().stream().forEach(data->{
                if(data.getAlarmType()==1){
                    data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmSignalId()));
                }else{
                    data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmId()));
                }
        });
        return new Response().set(1,pageInfo);
    }
 
    /**
     *  查询实施表中所有的main_id
     * @return
     */
    public List<Integer> getAllMainIds(){
        return mapper.getAllMainIds();
    }
}