whyczh
2021-12-09 f59d415d5a63131375f5f35b5735690a32fd8ecd
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.factory.BattinfGroupFactory;
import com.whyc.mapper.BattInfMapper;
import com.whyc.pojo.Battinf;
import com.whyc.pojo.PowerInf;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class BattInfService {
    @Resource
    private BattInfMapper battInfMapper;
 
    public int searchMaxBattgroupId_zj(){
        int id = battInfMapper.getMaxBattGroupId_zj();
        return id+1;
    }
 
    public String searchMaxId_zj(){
        int id = Integer.valueOf(battInfMapper.getMaxStationId_zj());
        return (id+1)+"";
    }
 
    public int searchMaxDevId(Integer fbsDeviceId){
        int devId = battInfMapper.getMaxDevId(fbsDeviceId);
        if(devId==0){
            int length = String.valueOf(fbsDeviceId).length();
            switch (length){
                case 3:
                    devId = fbsDeviceId*1000000;break;
                case 4:
                    devId = fbsDeviceId*100000;break;
                case 5:
                    devId = fbsDeviceId*10000;break;
                case 6:
                    devId = fbsDeviceId*1000;break;
                /*case 9100:
                case 9110:
                case 9120:
                case 9605:
                    devId = fbsDeviceId*100000;break;
                case 61850:
                case 71850:
                    devId = fbsDeviceId*10000;break;
                default:
                    devId= fbsDeviceId*100000;break;*/
            }
        }
        devId+=1;
 
        return devId;
    }
 
 
    public Response searchAllStationName1 (Integer uId){
        List<String> list = battInfMapper.getStationName1ByUserId(uId);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response searchAllStationName2 (Integer uId,String stationName1){
        List<String> list = battInfMapper.getStationName2ByUseridAndSt1(uId,stationName1);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response searchAllStationName5 (Integer uId,String stationName1,String stationName2){
        List<String> list = battInfMapper.getStationName5ByUseridAndSt1AndSt2(stationName1,stationName2,uId);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response searchAllStationName(Integer uId,String stationName1,String stationName2,String stationName5){
        List<Battinf> list = battInfMapper.getAllStationName(uId,stationName1,stationName2,stationName5);
        return new Response().set(1,list,"查询成功");
    }
 
 
    public Response searchBattGroupByStationName (Integer uId,String stationName1,String stationName){
        List<Battinf> list = battInfMapper.getBattgroupListByStationNameAndStationName1(uId,stationName1,stationName);
        return new Response().set(1,list,"查询成功");
    }
 
    public Response searchStationNameInGroup(Integer uId,String stationName1){
        List<String> list = battInfMapper.getStationNameInGroup(uId,stationName1);
        return new Response().set(1,list,"查询成功");
    }
 
 
    public Response add(Battinf battinf,Integer userId){
        int battGroupId = searchMaxBattgroupId_zj();//BattinfGroupFactory.searchMaxBattgroupId();
        battinf.setBattGroupId(battGroupId);
        String stationId = searchMaxId_zj();//BattinfGroupFactory.searchStationId();
        battinf.setStationId(stationId);
        int dev_id = searchMaxDevId(battinf.getFBSDeviceId().intValue());
        Battinf bst3 = battInfMapper.judgeBattStationName3(battinf);
        if (bst3!=null){
            battinf.setStationId(bst3.getStationId());
            Battinf bst = battInfMapper.judgeBattStationName(battinf.getStationName(),battinf.getFBSDeviceName());
            if (bst!=null){
                battinf.setFBSDeviceId(bst.getFBSDeviceId());
            }else {
                battinf.setFBSDeviceId((long) dev_id);
            }
        }else {
            battinf.setStationId(stationId);
            battinf.setFBSDeviceId((long) dev_id);
        }
        battInfMapper.insert(battinf);
        battInfMapper.insertUserBattgroupBaojigroupBattgroup(battinf.getStationId(),battinf.getBattGroupId());
        battInfMapper.insertUserBattgroupBaojigroupBattgroupSelect(battinf.getStationId(),battinf.getBattGroupId(),userId);
        return new Response().set(1,battinf,"添加成功");
    }
 
    public Response searchInfo(int pageNum,int pageSize,Integer userId,String stationName1,String stationName2,String stationName5,String stationName3){
        PageHelper.startPage(pageNum,pageSize);
        List<Battinf> list = battInfMapper.searchInform(userId, stationName1, stationName2,stationName5, stationName3);
        PageInfo<Battinf> pageInfo = new PageInfo<>(list);
        return new Response().set(1,pageInfo,"查询成功");
    }
 
    public void deleteByBattgroupId(Integer battgroupId){
        QueryWrapper<Battinf> wrapper = new QueryWrapper<Battinf>().eq("battgroupId",battgroupId);
        battInfMapper.delete(wrapper);
    }
 
    public Response update(Battinf battinf){
        if (battInfMapper.updateById(battinf)>0){
            return new Response().set(1,"更新成功");
        }else {
            return new Response().set(0,"更新失败");
        }
    }
 
    public Response searchBattProducer(){
        List<String> list = battInfMapper.getAllBattProducer();
        return new Response().set(1,list);
    }
 
 
 
    public void addBatch(List<Battinf> battInfList){
        battInfMapper.insertBatchSomeColumn(battInfList);
    }
 
 
    public List<Battinf> getStationList(int userId) {
        return battInfMapper.getStationList(userId);
    }
}