| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.sun.javafx.collections.MappingChange; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BattInfMapper; |
| | | import com.whyc.mapper.BattRtdataMapper; |
| | | import com.whyc.pojo.BattRtdata; |
| | | import com.whyc.pojo.BattRtstate; |
| | | import com.whyc.pojo.Battinf; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Resource |
| | | private BattRtdataMapper mapper; |
| | | |
| | | @Resource |
| | | private BattInfMapper binfMapper; |
| | | //根据电池组id查询该电池组中所有电池信息(图表数据) |
| | | @Transactional |
| | | public Response serchByCondition(int battGroupId) { |
| | |
| | | if(dataList!=null && dataList.size()>0) { |
| | | Map<Long, List<BattRtdata>> map = dataList.stream().collect(Collectors.groupingBy(BattRtdata::getNum)); |
| | | Set<Long> keySet = map.keySet(); |
| | | //keySet = keySet.stream().sorted(Comparator.comparingLong(Long::intValue)).collect(Collectors.toCollection(LinkedHashSet::new)); |
| | | Iterator<Long> iterator = keySet.iterator(); |
| | | while (iterator.hasNext()){ |
| | | Long next = iterator.next(); |
| | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public void insertMonRecord(int battGroupId, List<Integer> monNumList) { |
| | | mapper.insertMonRecord(battGroupId,monNumList); |
| | | } |
| | | |
| | | public void deleteWhenMonNumBeyond(int battGroupId, int mon_cnt) { |
| | | mapper.deleteWhenMonNumBeyond(battGroupId,mon_cnt); |
| | | } |
| | | |
| | | public int seachBattMaxMonNum(int battGroupId) { |
| | | QueryWrapper<BattRtdata> query = Wrappers.query(); |
| | | query.select("mon_num").eq("BattGroupId", battGroupId).orderByDesc("mon_num").last("limit 1"); |
| | | BattRtdata battRtdata = mapper.selectOne(query); |
| | | if (battRtdata == null) { |
| | | return 0; |
| | | } |
| | | return battRtdata.getMonNum(); |
| | | } |
| | | |
| | | //并联电源多组单体数据 |
| | | public Response serch9141ByCondition(int devId) { |
| | | List<BattRtdata> list = mapper.serch9141ByCondition(devId); |
| | | return new Response().setII(1, list.size() > 0 ? true : false, list, "9141数据"); |
| | | } |
| | | |
| | | /*public void addBatch(List<BattRtdata> battDataList) { |
| | | mapper.addBatch(battDataList); |
| | | }*/ |
| | | |
| | | public void addOrUpdate(List<BattRtdata> battDataList) { |
| | | List<BattRtdata> updateList = new LinkedList<>(); |
| | | List<BattRtdata> addList = new LinkedList<>(); |
| | | |
| | | //如果存在电池组则更新所有 |
| | | //不存在电池组则新增 |
| | | //TODO 这里是提示,不是待办.重要!!!!!!如果电池组内新增了单体数,需要临时删除掉单体实时表数据. 这样会加载新的所有单体 |
| | | List<Integer> battGroupIdList = battDataList.stream().map(BattRtdata::getBattGroupId).distinct().collect(Collectors.toList()); |
| | | QueryWrapper<BattRtdata> query = Wrappers.query(); |
| | | query.select("distinct BattGroupId as BattGroupId").in("BattGroupId",battGroupIdList); |
| | | List<BattRtdata> battStateListInDB = mapper.selectList(query); |
| | | List<Integer> battGroupIdListInDB = battStateListInDB.stream().map(BattRtdata::getBattGroupId).distinct().collect(Collectors.toList()); |
| | | |
| | | for (BattRtdata battData : battDataList) { |
| | | if(battGroupIdListInDB.contains(battData.getBattGroupId())){ //更新 |
| | | updateList.add(battData); |
| | | }else{ //新增 |
| | | addList.add(battData); |
| | | } |
| | | } |
| | | if(updateList.size()>0){ |
| | | mapper.updateBatch(updateList); |
| | | } |
| | | if(addList.size()>0) { |
| | | mapper.addBatch(battDataList); |
| | | } |
| | | } |
| | | //查询电池组单体实时信息 |
| | | public Response serchPowerHr6159(int devId) { |
| | | //1.取电池组id按顺序组1组2 |
| | | QueryWrapper<Battinf> query = Wrappers.query(); |
| | | query.select("distinct BattGroupId,GroupIndexInFBSDevice ").eq("FBSDeviceId",devId).orderByAsc("GroupIndexInFBSDevice"); |
| | | List<Battinf> infList= binfMapper.selectList(query); |
| | | Map<Integer,List> map=new HashMap<>(); |
| | | for (Battinf binf:infList) { |
| | | int battGroupId=binf.getBattGroupId(); |
| | | int groupIndex=binf.getGroupIndexInFBSDevice(); |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | wrapper.eq("BattGroupId",battGroupId); |
| | | List<BattRtdata> rtdataList = mapper.selectList(wrapper); |
| | | map.put(groupIndex,rtdataList); |
| | | } |
| | | return new Response().setII(1,map.size()>0,map,"查询电池组单体实时信息"); |
| | | } |
| | | } |