whyclxw
2025-05-17 feaaad2d357f5084d21f14a6929fe208b4c4ad0e
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
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;
 
 
    /*添加电源
    1.判断当前用户是否是包组用户
    2.判断机房是否存在,若存在则在机房下添加电源,若不存在则新建机房+新建电源
    3.电源需要编号,powerNum编号,电源名称自动生成通讯电源+powerNum
    */
    @Transactional
   public void addPower(PowerInf addpinf) {
        //机房信息
        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);
        }
        //电源需要编号,powerNum编号,电源名称自动生成通讯电源+powerNum
        int powerNum=mapper.getMaxPowerNum(stationId);
        if(powerNum==0){
            powerNum=1;
        }else{
            powerNum+=1;
        }
        //再添加电源信息
        addpinf.setStationId(stationId);
        addpinf.setPowerNum(powerNum);
        addpinf.setPowerName("通讯电源"+powerNum);
        //获取对应的电源id
        powerId = mapper.getMaxPowerId();
        if (powerId == 0) {//数据库中没有站点
            powerId = 10001;
        } else {
            powerId += 1;
        }
        addpinf.setPowerId(powerId);
        mapper.insert(addpinf);
    }
    //获取电源品牌(下拉)
    public Response getCompanyByUid(Integer uid) {
        List<String> list=mapper.getCompanyByUid(uid);
        return new Response().setII(1,list.size()>0,list,"获取电源品牌(下拉)");
    }
    //获取电源型号(下拉)
    public Response getPowerModelByUid(Integer uid) {
        List<String> list=mapper.getPowerModelByUid(uid);
        return new Response().setII(1,list.size()>0,list,"获取电源型号(下拉)");
    }
}