lxw
2023-05-25 7b7e2cb0a59221fd0e7f77a471bd22e42ece4911
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.PowerInfMapper;
import com.whyc.pojo.PowerInf;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;
 
@Service
public class PowerInfService {
    @Resource
    private PowerInfMapper mapper;
 
    public int add(PowerInf powerInf){
        return mapper.insert(powerInf);
    }
 
    public void updateByPowerDeviceId(PowerInf powerInf){
        UpdateWrapper<PowerInf> wrapper = new UpdateWrapper<PowerInf>().eq("PowerDeviceId",powerInf.getPowerDeviceId());
        mapper.update(powerInf,wrapper);
    }
 
    public void deleteByPowerDeviceId(Integer powerDeviceId){
       QueryWrapper<PowerInf> wrapper = new QueryWrapper<PowerInf>().eq("PowerDeviceId",powerDeviceId);
        mapper.delete(wrapper);
    }
 
 
    public List<String> delEmptyData(List<String> list){
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            String str = it.next();
            if ("".equals(str.trim())){
                it.remove();
            }
        }
        return list;
    }
 
 
    public Response getProvincesContainBatt(){
        List<String> list= mapper.getProvincesContainBatt();
        delEmptyData(list);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getCitiesContainBatt(String stationName1){
        List<String> list= mapper.getCitiesContainBatt(stationName1);
        delEmptyData(list);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getDistrictsContainBatt(String stationName1,String stationName2){
        List<String> list= mapper.getDistrictsContainBatt(stationName1,stationName2);
        delEmptyData(list);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getProvinces(Long uId){
        List<String> list= mapper.getProvinces(uId);
        delEmptyData(list);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getCities(Long uId,String stationName1){
        List<String> list= mapper.getCities(uId,stationName1);
        delEmptyData(list);
        return new Response().set(1,list,"查询成功");
    }
    public Response getDistricts(Long uId,String stationName1,String stationName2){
        List<String> list= mapper.getDistricts(uId,stationName1,stationName2);
        delEmptyData(list);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getExistStations(String stationName1,String stationName2,String stationName5){
        List<PowerInf> list = mapper.getExistStations(stationName1,stationName2,stationName5);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getStations(Long userId,String stationName5){
        List<PowerInf> list = mapper.getStations(userId,stationName5);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response getPowerDevicesPage(int pageNum,int pageSize,Long uId,String stationId, String stationName1,String stationName2,String stationName5){
        PageHelper.startPage(pageNum,pageSize);
        List<PowerInf> list = mapper.getPowerDevicesPage(uId,stationId, stationName1, stationName2,stationName5);
        PageInfo<PowerInf> pageInfo = new PageInfo<>(list);
        return new Response().set(1,pageInfo,"查询成功");
    }
 
    public Response getPowerDevices(String stationId){
        QueryWrapper<PowerInf> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("stationid",stationId);
        List<PowerInf> list = mapper.selectList(queryWrapper);
        return new Response().set(1,list,"查询成功");
    }
 
    //查询某个电源的详细信息
    public Response getInfoById(int powerDeviceId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("PowerDeviceId",powerDeviceId);
        List list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
 
    //在线监测-实时监控-获取配电柜的实时数据
    public Response getPowerInfoById(int powerDeviceId) {
        //acdcinfMapper.getInfo(powerDeviceId);
        return new Response().set(1);
    }
 
    public int getNum(int userId) {
        return mapper.getNum(userId);
    }
 
    //管理员首页:电源信息
    public List<PowerInf> getPwrdevInfAnalysis(int userId) {
        List<PowerInf> list = mapper.getPwrdevInfAnalysis(userId);
        return list;
    }
 
    public Response updateExceptionCause(PowerInf powerInf) {
        //非空校验
        if(powerInf.getExceptionCause()==null || powerInf.getExceptionCause().isEmpty()){
            return new Response().set(1,false,"异常原因不能为空");
        }
        mapper.updateById(powerInf);
        return new Response().set(1,true,"填写完成");
    }
 
    public Response updateCancelExceptionCause(int num) {
        UpdateWrapper<PowerInf> update = Wrappers.update();
        update.set("exception_cause",null).set("exception_cause_analysis",null).eq("num",num);
        mapper.update(null,update);
        return new Response().setII(1,"取消成功");
    }
 
    public Response getExceptionCause(int num) {
        QueryWrapper<PowerInf> query = Wrappers.query();
        query.select("StationName","PowerProducer","exception_cause","exception_cause_analysis").eq("num",num);
        PowerInf powerInf = mapper.selectOne(query);
        return new Response().set(1,powerInf);
    }
}