whyclxw
2024-02-29 d883ad10fa92a9e5b04fc3408c76a67e24fc355e
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.whyc.dto.Response;
import com.whyc.mapper.BattInfMapper;
import com.whyc.mapper.NjHomeStationMapper;
import com.whyc.mapper.PowerInfMapper;
import com.whyc.mapper.StationInfMapper;
import com.whyc.pojo.Battinf;
import com.whyc.pojo.NjHomeStation;
import com.whyc.pojo.PowerInf;
import com.whyc.pojo.StationInf;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
 
@Service
public class NjHomeStationService {
    @Resource
    private NjHomeStationMapper mapper;
 
    @Resource
    private BattInfMapper  battInfMapper;
 
    @Resource
    private StationInfMapper stationInfMapper;
 
    @Resource
    private PowerInfMapper powerInfMapper;
    //获取首页机房配置信息
    public NjHomeStation getStation() {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.last("limit 1");
        wrapper.orderByAsc("num");
        NjHomeStation njHomeStation=mapper.selectOne(wrapper);
        return njHomeStation;
    }
    //获取首页机房配置信息
    public Response getStationConfig() {
        NjHomeStation njHomeStation=getStation();
        if(njHomeStation!=null){
            //Map<String,Object> map=new HashMap<>();
            //获取battinf信息
            /*QueryWrapper wrapperBinf=new QueryWrapper();
            wrapperBinf.eq("BattGroupId",njHomeStation.getBattgroupId());
            wrapperBinf.last("limit 1");
            Battinf binf=battInfMapper.selectOne(wrapperBinf);
            map.put("binf",binf);*/
 
            //获取statinf信息
            QueryWrapper wrapperSinf=new QueryWrapper();
            wrapperSinf.eq("stationId",njHomeStation.getStationId());
            wrapperSinf.last("limit 1");
            StationInf sinf=stationInfMapper.selectOne(wrapperSinf);
            ///map.put("sinf",sinf);
/*
            //获取powerinf信息
            QueryWrapper wrapperPinf=new QueryWrapper();
            wrapperPinf.eq("PowerDeviceId",njHomeStation.getPowerDevId());
            wrapperPinf.last("limit 1");
            PowerInf pinf=powerInfMapper.selectOne(wrapperPinf);
            map.put("pinf",pinf);*/
            return new Response().setII(1,true,sinf,"获取首页机房配置信息");
        }else{
            return new Response().set(1,false,"获取首页机房配置信息");
        }
 
    }
   //编辑首页机房配置信息
    public Response updateStationConfig(int stationId) {
        NjHomeStation njHomeStation=getStation();
        NjHomeStation nj=getStationById(stationId);
        if(njHomeStation!=null){//判断表中是否有数据
            mapper.update(nj, null);
        }else{
            mapper.insert(nj);
        }
        return new Response().set(1,true);
    }
    //获根据stationId获取信息
    public NjHomeStation getStationById(int stationId) {
        NjHomeStation njHomeStation=new NjHomeStation();
        njHomeStation.setStationId(stationId);
        //获取battinf信息
        QueryWrapper wrapperBinf=new QueryWrapper();
        wrapperBinf.eq("stationId",stationId);
        wrapperBinf.last("limit 1");
        Battinf binf=battInfMapper.selectOne(wrapperBinf);
        if(binf!=null){
            njHomeStation.setBattgroupId(binf.getBattGroupId());
            njHomeStation.setDevId(Integer.valueOf(String.valueOf(binf.getFBSDeviceId())));
        }else {
            njHomeStation.setBattgroupId(0);
            njHomeStation.setDevId(0);
        }
 
 
        //获取powerinf信息
        QueryWrapper wrapperPinf=new QueryWrapper();
        wrapperPinf.eq("stationId",stationId);
        wrapperPinf.last("limit 1");
        PowerInf pinf=powerInfMapper.selectOne(wrapperPinf);
        if(pinf!=null){
            njHomeStation.setPowerDevId(pinf.getPowerDeviceId());
        }else {
            njHomeStation.setPowerDevId(0);
        }
        return njHomeStation;
    }
    //添加默认首页机房配置信息
    public Response addStationConfig(NjHomeStation njHomeStation) {
        //先清空表后添加
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.ge("num",0);
        mapper.delete(wrapper);
        mapper.insert(njHomeStation);
        return new Response().set(1,true);
    }
}