whyclxw
2024-02-29 703a323cd80d3d51524742c1e5f25db1155c60fb
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
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,map,"获取首页机房配置信息");
        }else{
            return new Response().set(1,false,"获取首页机房配置信息");
        }
 
    }
   //编辑首页机房配置信息
    public Response updateStationConfig(NjHomeStation njHomeConfig) {
        mapper.update(njHomeConfig, null);
        return new Response().set(1,true);
    }
    //添加默认首页机房配置信息
    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);
    }
}