whyclxw
2025-05-15 476ccf8a7dcd23806dd49944659ec34575047c40
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.PowerDto;
import com.whyc.dto.Response;
import com.whyc.mapper.PowerInfMapper;
import com.whyc.mapper.StationInfMapper;
import com.whyc.pojo.db_station.PowerInf;
import com.whyc.pojo.db_station.StationInf;
import com.whyc.pojo.db_user.User;
import com.whyc.util.ActionUtil;
import org.apache.commons.math3.analysis.function.Power;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
public class PowerInfService {
    @Autowired(required = false)
    private PowerInfMapper mapper;
 
    @Autowired(required = false)
    private StationInfMapper sinfMapper;
 
    @Autowired(required = false)
    private BaojigroupService bjService;
 
    //添加电源
    @Transactional
   public Response addPower(PowerInf addpinf) {
       //先校验当前用户是否存在包机组不存在则不让添加电源
       User user= ActionUtil.getUser();
       int flag=bjService.checkUserBaojiGroup(user.getId());
       if(flag==0){
           return new Response().set(1,false,"当前用户不存在包机组");
       }
        //机房信息
        StationInf addsinf= addpinf.getSinf();
        //判断添加锁的时候机房是不是新机房
        String fullName=addsinf.getProvice()+"_"+addsinf.getCity()+"_"+addsinf.getCountry()+"_"+addsinf.getStationName();
        //判断机房是否存在
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("full_name",fullName);
        wrapper.last("limit 1");
        StationInf sinf=sinfMapper.selectOne(wrapper);
        int stationId=0;
        int powerId=0;
        if(sinf!=null){
            stationId=sinf.getStationId();
        }else {
            //获取对应的机房id
            stationId = sinfMapper.getMaxStationId();
            if (stationId == 0) {//数据库中没有站点
                stationId = 40000001;
            } else {
                stationId += 1;
            }
            addsinf.setFullName(fullName);
            addsinf.setStationId(stationId);
            sinfMapper.insert(addsinf);
        }
            //再添加电源信息
            addpinf.setStationId(stationId);
            //获取对应的电源id
            powerId = mapper.getMaxPowerId();
            if (powerId == 0) {//数据库中没有站点
                powerId = 10001;
            } else {
                powerId += 1;
            }
            addpinf.setPowerId(powerId);
            mapper.insert(addpinf);
            return new Response().set(1, true, "添加电源");
    }
    //删除电源
    public Response delPower(Integer pid) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("power_id",pid);
        mapper.delete(wrapper);
        return new Response().set(1,true);
    }
    //修改电源
    public Response updatePower(PowerInf pinf) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("power_id",pinf.getPowerId());
        if(pinf.getPowerName()!=null){
            wrapper.set("power_name",pinf.getPowerName());
        }
        if(pinf.getCompany()!=null){
            wrapper.set("company",pinf.getCompany());
        }
        if(pinf.getModel()!=null){
            wrapper.set("model",pinf.getModel());
        }
        if(pinf.getProtocol()!=null){
            wrapper.set("protocol",pinf.getProtocol());
        }
        if(pinf.getPowerIp()!=null){
            wrapper.set("power_ip",pinf.getPowerIp());
        }
        mapper.update((PowerInf) ActionUtil.objeNull,wrapper);
        return new Response().set(1,true);
    }
    //查询电源
    public Response getPower(PowerDto dto) {
        User user= ActionUtil.getUser();
        dto.setUid(user.getId());
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<PowerInf> list=mapper.getPower(dto);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询电源");
    }
 
}