| | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.BattInfAndEnduranceDTO; |
| | | import com.whyc.dto.BatteryRTState; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BattInfMapper; |
| | | import com.whyc.mapper.BattinfUpdateRecordMapper; |
| | | import com.whyc.mapper.CommonMapper; |
| | | import com.whyc.pojo.Battinf; |
| | | import com.whyc.pojo.BattinfUpdateRecord; |
| | | import com.whyc.pojo.PowerInf; |
| | | import com.whyc.pojo.StationInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.MathUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.core.env.Environment; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private BattInfMapper battInfMapper; |
| | | @Resource |
| | | private BattinfUpdateRecordMapper battinfUpdateRecordMapper; |
| | | @Resource |
| | | private Environment environment; |
| | | @Resource |
| | | private PowerInfService powerInfService; |
| | | @Autowired |
| | | private StationInfService stationInfService; |
| | | @Resource |
| | | private CommonMapper commonMapper; |
| | | @Autowired |
| | | private BattRtdataService battRtdataService; |
| | | @Autowired |
| | | private BattRsalarmService battRsalarmService; |
| | | @Autowired |
| | | private BattRtalarmService battRtalarmService; |
| | | @Autowired |
| | | private ProcessSurveyService processSurveyService; |
| | | @Autowired |
| | | private BatttestdataInfService testInfService; |
| | | |
| | | public int searchMaxBattgroupId_zj() { |
| | | Integer id = battInfMapper.getMaxBattGroupId_zj(); |
| | |
| | | Integer id = battInfMapper.getMaxStationId_zj(); |
| | | id = id == null ? id = 0 : id; |
| | | return (id + 1) + ""; |
| | | } |
| | | |
| | | /** |
| | | * 获取下个站点编号,替代 searchMaxId_zj |
| | | * @return |
| | | */ |
| | | public String getNextStationId() { |
| | | String maxStationId = stationInfService.getMaxStationId(); |
| | | return (Integer.parseInt(maxStationId) + 1) + ""; |
| | | } |
| | | |
| | | public int searchMaxDevId(Integer fbsDeviceId){ |
| | |
| | | return new Response().set(1,list,"查询成功"); |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | public Response add(Battinf battinf,Integer userId){ |
| | | int battGroupId = searchMaxBattgroupId_zj();//BattinfGroupFactory.searchMaxBattgroupId(); |
| | | battinf.setBattGroupId(battGroupId); |
| | | String stationId = searchMaxId_zj();//BattinfGroupFactory.searchStationId(); |
| | | //String stationId = searchMaxId_zj();//BattinfGroupFactory.searchStationId(); |
| | | //从站点表中获取下个站点id |
| | | String stationId = getNextStationId();//BattinfGroupFactory.searchStationId(); |
| | | battinf.setStationId(stationId); |
| | | int dev_id = searchMaxDevId(battinf.getFBSDeviceId().intValue()); |
| | | Battinf bst3 = battInfMapper.judgeBattStationName3(battinf); |
| | | if (bst3!=null){ |
| | | if (bst3!=null){ //存在,无需新建站点记录 |
| | | battinf.setStationId(bst3.getStationId()); |
| | | Battinf bst = battInfMapper.judgeBattStationName(battinf.getStationName(),battinf.getFBSDeviceName()); |
| | | if (bst!=null){ |
| | |
| | | battinf.setFBSDeviceId((long) dev_id); |
| | | } |
| | | }else { |
| | | //站点不存在,需要新建站点记录 |
| | | StationInf station = new StationInf(); |
| | | station.setStationId(stationId); |
| | | station.setStationName(battinf.getStationName()); |
| | | station.setStationName1(battinf.getStationName1()); |
| | | station.setStationName2(battinf.getStationName2()); |
| | | station.setStationName3(battinf.getStationName3()); |
| | | station.setStationName4(battinf.getStationName4()); |
| | | station.setStationName5(battinf.getStationName5()); |
| | | stationInfService.insertStation(station); |
| | | |
| | | battinf.setStationId(stationId); |
| | | battinf.setFBSDeviceId((long) dev_id); |
| | | } |
| | | battInfMapper.insert(battinf); |
| | | battInfMapper.insertUserBattgroupBaojigroupBattgroup(battinf.getStationId(),battinf.getBattGroupId()); |
| | | battInfMapper.insertUserBattgroupBaojigroupBattgroupSelect(battinf.getStationId(),battinf.getBattGroupId(),userId); |
| | | run_cmd(); |
| | | doAfterBattGroupChange(battinf.getBattGroupId()); |
| | | //run_cmd(); |
| | | return new Response().set(1,battinf,"添加成功"); |
| | | } |
| | | |
| | | /**电源添加前校验是否站点存在,从电池表+电源表查询*/ |
| | | /** |
| | | * 新:从站点表校验站点是否存在 |
| | | * 旧:电源添加前校验是否站点存在,从电池表+电源表查询,弃用 |
| | | * */ |
| | | public Battinf judgeBattStationName3(PowerInf powerInf){ |
| | | Battinf battinf = new Battinf(); |
| | | battinf.setStationName1(powerInf.getStationName1()); |
| | |
| | | return new Response().set(1,pageInfo,"查询成功"); |
| | | } |
| | | |
| | | @Transactional |
| | | public void deleteByBattgroupId(Integer battgroupId){ |
| | | QueryWrapper<Battinf> wrapper = new QueryWrapper<Battinf>().eq("battgroupId",battgroupId); |
| | | battInfMapper.delete(wrapper); |
| | | doAfterBattGroupChange(battgroupId); |
| | | } |
| | | |
| | | public Response update(Battinf battinf){ |
| | | if (battInfMapper.updateById(battinf)>0){ |
| | | run_cmd(); |
| | | return new Response().set(1,"更新成功"); |
| | | }else { |
| | | return new Response().set(0,"更新失败"); |
| | | @Transactional |
| | | public Response update(Battinf battinf) { |
| | | //1.查询更新前的记录 |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | wrapper.eq("battGroupId", battinf.getBattGroupId()); |
| | | wrapper.last("limit 1"); |
| | | Battinf binf = battInfMapper.selectOne(wrapper); |
| | | binf.setUpdateReason(battinf.getUpdateReason()); |
| | | if (battInfMapper.updateById(battinf) > 0) { |
| | | doAfterBattGroupChange(battinf.getBattGroupId()); |
| | | //run_cmd(); |
| | | //将更新前的记录记录下来BattinfUpdateRecord |
| | | BattinfUpdateRecord binBattinfUpdateRecord = new BattinfUpdateRecord(); |
| | | BeanUtils.copyProperties(binf, binBattinfUpdateRecord); |
| | | binBattinfUpdateRecord.setRecordTime(new Date()); |
| | | binBattinfUpdateRecord.setUpdateName(ActionUtil.getUser().getUName()); |
| | | battinfUpdateRecordMapper.insert(binBattinfUpdateRecord); |
| | | return new Response().set(1, "更新成功"); |
| | | } else { |
| | | return new Response().set(0, "更新失败"); |
| | | } |
| | | } |
| | | |
| | |
| | | for (Battinf battinf:battinfs) { |
| | | battInfMapper.updateById(battinf); |
| | | } |
| | | run_cmd(); |
| | | //run_cmd(); |
| | | return new Response().set(1,"更新成功"); |
| | | } |
| | | |
| | |
| | | int yearBetweenFiveAndSeven = 0; |
| | | int yearAboveSeven = 0; |
| | | List<Integer> list = battInfMapper.findUseYear(uId); |
| | | //查询3年内,3-5年,5-7年,7年以上,含头不含尾 |
| | | for (int year:list){ |
| | | //查询1年内~7年内,7年以上,含头不含尾 |
| | | map.put("1年内", (int) list.stream().filter(item -> item <1).count()); |
| | | map.put("2年内", (int) list.stream().filter(item -> item < 2).count()); |
| | | map.put("3年内", (int) list.stream().filter(item -> item < 3).count()); |
| | | map.put("4年内", (int) list.stream().filter(item -> item < 4).count()); |
| | | map.put("5年内", (int) list.stream().filter(item -> item < 5).count()); |
| | | map.put("6年内", (int) list.stream().filter(item -> item < 6).count()); |
| | | map.put("7年内", (int) list.stream().filter(item -> item < 7).count()); |
| | | map.put("7年以上", (int) list.stream().filter(item -> item >= 7).count()); |
| | | |
| | | /*for (int year:list){ |
| | | if(year<3){ |
| | | yearBelowThree+=1; |
| | | }else if(year<5){ |
| | |
| | | map.put("3年内",yearBelowThree); |
| | | map.put("3-5年",yearBetweenThreeAndFive); |
| | | map.put("5-7年",yearBetweenFiveAndSeven); |
| | | map.put("7年以上",yearAboveSeven); |
| | | map.put("7年以上",yearAboveSeven);*/ |
| | | return new Response().set(1,map,"查询成功"); |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * yearCode: |
| | | * 1:3年以内 |
| | | * 2:3-5年 |
| | | * 3:5到7年 |
| | | * 4:7年以上 |
| | | * @param yearCode |
| | | * 1:1年以内 |
| | | * ... |
| | | * 7:7年以内 |
| | | * 8:7年以上 |
| | | * @param year |
| | | * @param uId |
| | | * @return |
| | | */ |
| | | public Response findBattProducerInfoByYearCode(int yearCode,int uId){ |
| | | List<BattInfAndEnduranceDTO> list = battInfMapper.findBattProducerInfoByYearCode(yearCode,uId); |
| | | public Response findBattProducerInfoByYearCode(int year,int uId){ |
| | | List<BattInfAndEnduranceDTO> list = battInfMapper.findBattProducerInfoByYearCode(year,uId); |
| | | return new Response().set(1,list,"查询成功"); |
| | | } |
| | | |
| | |
| | | //取出电池组信息构建excel文件的名称 |
| | | public String serchExcelName(int battGroupId) { |
| | | Battinf binf = battInfMapper.serchExcelName(battGroupId); |
| | | String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + ActionUtil.sdfwithOutday.format(binf.getBattProductDate()).replace("_", "年") + "月-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName(); |
| | | String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + ActionUtil.sdfwithOutday.format(binf.getBattProductDate()).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName(); |
| | | return excelName; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取电池,设备,电源,机房站点 计数 |
| | | * 获取电池,设备,电源,机房站点 计数/管理元首页:基础资源信息 |
| | | * |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | public Response getDevCountMap(int userId) { |
| | | try { |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | int battGroupCount = battInfMapper.getBattGroupNum(userId); |
| | | int devCount = battInfMapper.getDevNum(userId); |
| | | int powerNum = powerInfService.getNum(userId); |
| | | List<StationInf> stationInfList = stationInfService.getStationInfList(userId); |
| | | int stationNum = stationInfService.getStation(userId); |
| | | int hrDisNum = testInfService.getHrQuarterZC(userId); |
| | | map.put("battGroupCount", battGroupCount); |
| | | map.put("devCount", devCount); |
| | | map.put("powerNum", powerNum); |
| | | map.put("stationNum",stationNum); |
| | | map.put("stationInfList",stationInfList); |
| | | map.put("checkCapNum",hrDisNum); |
| | | return new Response().setII(1,true, map,null); |
| | | }catch (Exception e){ |
| | | return new Response<>().set(1,false,"发生异常:"+e.getCause()); |
| | |
| | | public List<Battinf> getBattGroupList(int userId) { |
| | | return battInfMapper.getBattGroupList(userId); |
| | | } |
| | | /** |
| | | * 获取电池组的实际容量 |
| | | */ |
| | | public List<BatteryRTState> getBatteryCap(int userId){ |
| | | return battInfMapper.getBatteryCap(userId); |
| | | |
| | | //管理员首页:基础资源信息 |
| | | @Transactional |
| | | public Response getBattInfoAnalysis(int userId) { |
| | | try { |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | int battGroupCount = battInfMapper.getBattGroupNum(userId); |
| | | //电源机房总数 |
| | | int powerNum = powerInfService.getNum(userId); |
| | | //int monNum = battInfMapper.getMonCount(userId); |
| | | //电池机房总数 |
| | | //int battStationNum = battInfMapper.geStationCount(userId); |
| | | //总机房 |
| | | int stationNum = stationInfService.getStation(userId); |
| | | //设备数 |
| | | int deviceNum = battInfMapper.getDevNum(userId); |
| | | /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3) |
| | | int hrDisNum = testInfService.getHrQuarter(userId); |
| | | * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下: |
| | | stop_type: |
| | | 2-放电时间到终止并且放电时间超过2小时 |
| | | 3-放电容量到终止 |
| | | 4-单体电压下限到终止 |
| | | 6-组端电压下限到终止*/ |
| | | int hrDisNum = testInfService.getHrQuarterZC(userId); |
| | | //map.put("monNum", monNum);//单体 |
| | | //map.put("battStationNum", battStationNum);//站点 |
| | | map.put("battGroupCount", battGroupCount);//电池组 |
| | | map.put("powerNum", powerNum);//电源 |
| | | map.put("stationNum", stationNum);//总机房 |
| | | map.put("hrDisNum", hrDisNum);//本年度核容放电电池组 |
| | | map.put("deviceNum", deviceNum);//本年度核容放电电池组 |
| | | return new Response().setII(1, true, map, "基础资源信息"); |
| | | } catch (Exception e) { |
| | | return new Response<>().set(1, false, "发生异常:" + e.getCause()); |
| | | } |
| | | } |
| | | |
| | | public int getCapAlarmNum(int userId){ |
| | | int capAlarmNum=0; |
| | | List<BatteryRTState> stateList = getBatteryCap(userId); |
| | | //查询容量告警阈值,暂定为70% TODO 后续从数据库读取 |
| | | for (int i = 0; i < stateList.size(); i++) { |
| | | BatteryRTState state = stateList.get(i); |
| | | Float batteryRealCap = state.getBatteryRealCap(); |
| | | Float capStd = state.getMonCapStd(); |
| | | Float realCapDivide = (Float) MathUtil.divide(batteryRealCap, capStd, MathUtil.TYPE_FLOAT); |
| | | if (realCapDivide <= 0.7) { |
| | | capAlarmNum++; |
| | | //管理员首页:站点信息 |
| | | public List<Battinf> getSateAnalysis(int userId) { |
| | | List<Battinf> list = battInfMapper.getSateAnalysis(userId); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 电池组 新增/编辑/删除后执行 |
| | | */ |
| | | public void doAfterBattGroupChange(int battGroupId){ |
| | | createBattState_RT_RamDB_Table(); |
| | | createBattData_RT_RamDB_Table(battGroupId); |
| | | createTb_Batt_RSAlarm_Table(); |
| | | createTb_Batt_RTAlarm_Table(battGroupId); |
| | | setUpThreadRestart(); |
| | | updateTb_App_Sys_AppServerTable(); |
| | | } |
| | | |
| | | /** |
| | | * 创建tb_batt_rtstate数据库表,并且将bd_al数组中的BattGroupId数据插入到表中" `db_ram_db`.tb_batt_rtstate" |
| | | */ |
| | | public void createBattState_RT_RamDB_Table() |
| | | { |
| | | //添加未录入电池组的组端信息 |
| | | commonMapper.createBattState_RT_RamDB_Table(); |
| | | } |
| | | |
| | | /** |
| | | * 创建tb_batt_rtdata表并且根据集合bd_al,向表中添加电池组id和mon_num 值 "`db_ram_db`.tb_batt_rtdata" |
| | | * @param battGroupId |
| | | */ |
| | | public void createBattData_RT_RamDB_Table(int battGroupId) |
| | | { |
| | | List<Battinf> battInfList = getBattInfList(battGroupId); |
| | | for (Battinf battInf : battInfList) { |
| | | int bg_id = battInf.getBattGroupId(); |
| | | System.out.println("执行到了:"+bg_id); |
| | | int mon_cnt = battInf.getMonCount(); |
| | | int pack_count = battInf.getPackCount(); |
| | | int FBSDeviceId = battInf.getFBSDeviceId().intValue(); |
| | | if (checkLiBTSDevType(FBSDeviceId) && pack_count > 0) { |
| | | mon_cnt = mon_cnt * pack_count; |
| | | } |
| | | if (mon_cnt > 0) { |
| | | //当前电池组在 tb_batt_rtdata 表中的最大单体个数 |
| | | int max_monnum = battRtdataService.seachBattMaxMonNum(bg_id); |
| | | if (mon_cnt > max_monnum) { |
| | | //需要从max_monnum开始添加单体记录 |
| | | List<Integer> monNumList = new LinkedList<>(); |
| | | for (int mc = max_monnum; mc < mon_cnt; mc++) { |
| | | monNumList.add(mc + 1); |
| | | } |
| | | battRtdataService.insertMonRecord(bg_id, monNumList); |
| | | } else if (mon_cnt < max_monnum) { |
| | | //删除当前电池组中超过单体个数的数据 |
| | | battRtdataService.deleteWhenMonNumBeyond(bg_id, mon_cnt); |
| | | } |
| | | } |
| | | } |
| | | return capAlarmNum; |
| | | } |
| | | |
| | | //管理元首页:基础资源信息 |
| | | public Response getBattInfoAnalysis(int userId) { |
| | | return new Response().set(1); |
| | | private List<Battinf> getBattInfList(int battGroupId) { |
| | | QueryWrapper<Battinf> query = Wrappers.query(); |
| | | query.select("BattGroupId","MonCount","FBSDeviceId","PackCount").eq("BattGroupId",battGroupId); |
| | | return battInfMapper.selectList(query); |
| | | } |
| | | |
| | | /** |
| | | * 创建组端信息告警记录表 `db_ram_db`.`tb_batt_rsalarm` |
| | | */ |
| | | public void createTb_Batt_RSAlarm_Table() { |
| | | //添加未录入电池组的组端信息 |
| | | battRsalarmService.addBattGroupIdsNoRecorded(); |
| | | } |
| | | |
| | | /** |
| | | * 创建单体信息告警记录表 "`db_ram_db`.`tb_batt_rtalarm`" |
| | | * @param battGroupId |
| | | */ |
| | | public void createTb_Batt_RTAlarm_Table(int battGroupId) { |
| | | List<Battinf> battInfList = getBattInfList(battGroupId); |
| | | for (Battinf battInf : battInfList) { |
| | | int bg_id = battInf.getBattGroupId(); |
| | | int mon_cnt = battInf.getMonCount(); |
| | | int pack_count = battInf.getPackCount(); |
| | | int FBSDeviceId = battInf.getFBSDeviceId().intValue(); |
| | | if (checkLiBTSDevType(FBSDeviceId) && pack_count > 0) { |
| | | mon_cnt = mon_cnt * pack_count; |
| | | } |
| | | if (mon_cnt > 0) { |
| | | //当前电池组在 tb_batt_rtalarm 表中的最大单体个数 |
| | | int max_monnum = battRtalarmService.seachBattRTAlarmMaxMonNum(bg_id); |
| | | if (mon_cnt > max_monnum) { |
| | | //需要从max_monnum开始添加单体记录 |
| | | List<Integer> monNumList = new LinkedList<>(); |
| | | for (int mc = max_monnum; mc < mon_cnt; mc++) { |
| | | monNumList.add(mc + 1); |
| | | } |
| | | battRtalarmService.insertMonRecord(bg_id, monNumList); |
| | | } else if (mon_cnt < max_monnum) { |
| | | //删除当前电池组中超过单体个数的数据 |
| | | battRtalarmService.deleteWhenMonNumBeyond(bg_id, mon_cnt); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置指定的线程重启[ 告警线程; ] "`web_site`.`tb_process_survey`" |
| | | */ |
| | | public void setUpThreadRestart() { |
| | | processSurveyService.setUpThreadRestart(); |
| | | } |
| | | |
| | | /** |
| | | * 让主程序重新导入单体数据关键字改成true db_app_sys.tb_app_sys |
| | | */ |
| | | public void updateTb_App_Sys_AppServerTable() |
| | | { |
| | | String tableName = commonMapper.existTable("db_app_sys", "tb_app_sys"); |
| | | if(tableName!=null) { //存在表 |
| | | commonMapper.updateTb_App_Sys_AppServerTable(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验当前设备是否是锂电BTS |
| | | * |
| | | * @param fbsDeviceId |
| | | * @return |
| | | */ |
| | | private boolean checkLiBTSDevType(int fbsDeviceId) { |
| | | if (fbsDeviceId / 100000 == 9131) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | //查询标称电压类别 |
| | | public Response searchMonVol() { |
| | | List<String> list = battInfMapper.searchMonVol(); |
| | | return new Response().setII(1, list.size() > 0 ? true : false, list, "查询标称电压类别"); |
| | | } |
| | | |
| | | //根据设备id查询电池组id(取第一个) |
| | | public Response searchBattGroupIdByDevId(int devId) { |
| | | String battGroupId = battInfMapper.searchBattGroupIdByDevId(devId); |
| | | return new Response().setII(1, battGroupId != null, battGroupId != null ? battGroupId : "0", "返回电池组id"); |
| | | } |
| | | } |