whyclxw
2021-12-16 8986f805e991fd4e9eee1cebb52f7b259c80c6e4
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
package com.whyc.service;
 
import com.alibaba.druid.pool.WrapperAdapter;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
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.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
@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);
    }
}