whyclxw
2025-05-16 3635a1df87e3a12d61b2a1bd7de2984475c4f71a
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.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) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("station_id",adddinf.getStationId());
        wrapper.eq("power_id",adddinf.getPowerId());
        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,"查询电池");
    }
 
}