whyclxw
2025-05-16 a6d1b5d325decd675c3d691c5a9ae6f130d3bd2c
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
123
124
125
126
127
128
129
130
131
132
133
134
135
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.BattDto;
import com.whyc.dto.PowerDto;
import com.whyc.dto.Response;
import com.whyc.mapper.BattInfMapper;
import com.whyc.pojo.db_station.BattInf;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
@Service
public class BattInfService {
    @Autowired(required = false)
    private BattInfMapper mapper;
 
    /*新建电池组(新的设备新的电池组)
     * @param binf
     * 1.在电源下新建设备,记录设备编号,devNum,设备名称为设备类型+devNum
     */
    public Response addDev(BattInf adddinf) {
        //检测电源下是否存在设备
        int devNum=mapper.getMaxDevNum(adddinf.getPowerId());
        if(devNum==0){
            devNum=1;
        }else{
            devNum+=1;
        }
        adddinf.setDevNum(devNum);
        adddinf.setDevName(adddinf.getDevType()+devNum);
        //获取对应的设备id,电池组
        int devId = mapper.getMaxdevId();
        int battGroupId=mapper.getMaxBattGroupId();
        if (devId == 0) {//数据库中没有站点
            devId = 10001;
        } else {
            devId += 1;
        }
        adddinf.setDevId(devId);
        adddinf.setBattgroupId(battGroupId);
        return new Response().set(1, true, "新建电池组(新的设备新的电池组)");
    }
    //设备下添加电源
    @Transactional
    public Response addBatt(BattInf addbinf) {
        //判断电池组是否存在
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("station_id",addbinf.getStationId());
        wrapper.eq("power_id",addbinf.getPowerId());
        wrapper.eq("dev_name",addbinf.getDevName());
        wrapper.eq("battgroup_name",addbinf.getBattgroupName());
        wrapper.last("limit 1");
        BattInf binf=mapper.selectOne(wrapper);
        int devId=0;
        int battGroupId=0;
        if(binf!=null){
            return new Response().set(1,false,"当前电源机房下已添加过该电池组");
        }else {
            //获取对应的设备id,电池组
            devId = mapper.getMaxdevId();
            battGroupId=mapper.getMaxBattGroupId();
            if (devId == 0) {//数据库中没有站点
                devId = 10001;
            } else {
                devId += 1;
            }
            if (battGroupId == 0) {//数据库中没有站点
                battGroupId = 10001;
            } else {
                battGroupId += 1;
            }
            addbinf.setDevId(devId);
            addbinf.setBattgroupId(battGroupId);
            addbinf.setCreateTime(new Date());
            mapper.insert(addbinf);
            return new Response().set(1, true, "添加电池组");
        }
    }
    //删除电源
    public Response delBatt(Integer bid) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("battgroup_id",bid);
        mapper.delete(wrapper);
        return new Response().set(1,true);
    }
    //修改电源
    public Response updateBatt(BattInf binf) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("battgroup_id",binf.getBattgroupId());
        if(binf.getBattgroupName()!=null){
            wrapper.set("battgroup_name",binf.getBattgroupName());
        }
        if(binf.getMonvolstd()!=null){
            wrapper.set("monvolstd",binf.getMonvolstd());
        }
        if(binf.getMoncapstd()!=null){
            wrapper.set("moncapstd",binf.getMoncapstd());
        }
        if(binf.getMonresstd()!=null){
            wrapper.set("monresstd",binf.getMonresstd());
        }
        if(binf.getProduct()!=null){
            wrapper.set("product",binf.getProduct());
        }
        if(binf.getMoncount()!=null){
            wrapper.set("moncount",binf.getMoncount());
        }
        if(binf.getModel()!=null){
            wrapper.set("model",binf.getModel());
        }
        mapper.update((BattInf) ActionUtil.objeNull,wrapper);
        return new Response().set(1,true);
    }
    //查询电池
    public Response getBatt(BattDto dto) {
        User user= ActionUtil.getUser();
        dto.setUid(user.getId());
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<BattInf> list=mapper.getBatt(dto);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询电池");
    }
 
}