| | |
| | | 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.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.InfoDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.Station.Provice; |
| | | import com.whyc.dto.StationDto; |
| | | import com.whyc.mapper.BaojigroupMapper; |
| | | import com.whyc.dto.Statistic.StationStic; |
| | | import com.whyc.mapper.StationInfMapper; |
| | | import com.whyc.pojo.db_station.StationInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.pojo.db_station.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Autowired(required = false) |
| | | private StationInfMapper mapper; |
| | | |
| | | |
| | | @Autowired(required = false) |
| | | private InfoChangeService changeService; |
| | | //获取左侧列表 |
| | | public Response getLeftStation(int uid) { |
| | | List<Provice> list=mapper.getLeftStation(uid); |
| | |
| | | return new Response().setII(1,list.size()>0,list,"获取所有的省份"); |
| | | } |
| | | //获取省下的市 |
| | | public Response getCityByUid(int uid, String stationName1) { |
| | | List<String> list=mapper.getCityByUid(uid,stationName1); |
| | | public Response getCityByUid(int uid, String provice) { |
| | | List<String> list=mapper.getCityByUid(uid,provice); |
| | | return new Response().setII(1,list.size()>0,list,"获取省下的市"); |
| | | } |
| | | //获取省市下的区县 |
| | | public Response getCountryByUid(int uid, String stationName1, String stationName2) { |
| | | List<String> list=mapper.getCountryByUid(uid,stationName1,stationName2); |
| | | public Response getCountryByUid(int uid, String provice, String city) { |
| | | List<String> list=mapper.getCountryByUid(uid,provice,city); |
| | | return new Response().setII(1,list.size()>0,list,"获取省市下的区县"); |
| | | } |
| | | //获取省市区县下的站点 |
| | | public Response getStationByUid(int uid, String stationName1, String stationName2, String stationName3) { |
| | | List<String> list=mapper.getStationByUid(uid,stationName1,stationName2,stationName3); |
| | | public Response getStationByUid(int uid, String provice, String city, String country) { |
| | | List<StationInf> list=mapper.getStationByUid(uid,provice,city,country); |
| | | return new Response().setII(1,list.size()>0,list,"获取省市区县下的站点"); |
| | | } |
| | | //添加机房 |
| | | public Response addStatiaon(StationInf addsinf) { |
| | | //判断添加锁的时候机房是不是新机房 |
| | | String fullName=addsinf.getProvice()+"_"+addsinf.getCity()+"_"+addsinf.getCountry()+"_"+addsinf.getStationName(); |
| | | //判断机房是否存在 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("full_name",fullName); |
| | | wrapper.last("limit 1"); |
| | | StationInf sinf=mapper.selectOne(wrapper); |
| | | int stationId=0; |
| | | if(sinf!=null){ |
| | | return new Response().set(1,false,"机房已存在"); |
| | | }else { |
| | | //获取对应的机房id |
| | | stationId=mapper.getMaxStationId(); |
| | | if(stationId==0){//数据库中没有站点 |
| | | stationId=40000001; |
| | | }else{ |
| | | stationId+=1; |
| | | } |
| | | StationInf newSinf=new StationInf(); |
| | | newSinf.setStationId(stationId); |
| | | newSinf.setStationName(fullName); |
| | | newSinf.setProvice(addsinf.getProvice()); |
| | | newSinf.setCity(addsinf.getCity()); |
| | | newSinf.setCountry(addsinf.getCountry()); |
| | | newSinf.setStationName(addsinf.getStationName()); |
| | | mapper.insert(newSinf); |
| | | return new Response().set(1,true,"添加机房"); |
| | | } |
| | | //获取站点下的电源(下拉) |
| | | public Response getPowerByUid(int uid, String provice, String city, String country, String stationName) { |
| | | List<PowerInf> list=mapper.getPowerByUid(uid,provice,city,country,stationName); |
| | | return new Response().setII(1,list.size()>0,list,"获取站点下的电源(下拉)"); |
| | | } |
| | | //删除机房 |
| | | public Response delStatiaon(Integer stationId) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("station_id",stationId); |
| | | mapper.delete(wrapper); |
| | | return new Response().set(1,true); |
| | | } |
| | | //修改机房 |
| | | public Response updateStatiaon(StationInf sinf) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("station_id",sinf.getStationId()); |
| | | if(sinf.getProvice()!=null){ |
| | | wrapper.set("provice",sinf.getProvice()); |
| | | } |
| | | if(sinf.getCity()!=null){ |
| | | wrapper.set("city",sinf.getCity()); |
| | | } |
| | | if(sinf.getCountry()!=null){ |
| | | wrapper.set("country",sinf.getCountry()); |
| | | } |
| | | if(sinf.getStationName()!=null){ |
| | | wrapper.set("station_name",sinf.getStationName()); |
| | | } |
| | | String fullName=sinf.getProvice()+"_"+sinf.getCity()+"_"+sinf.getCountry()+"_"+sinf.getStationName(); |
| | | wrapper.set("full_name",fullName); |
| | | mapper.update((StationInf) ActionUtil.objeNull,wrapper); |
| | | return new Response().set(1,true); |
| | | } |
| | | //查询机房 |
| | | public Response getStatiaon(StationDto dto) { |
| | | PageHelper.startPage(dto.getPageNum(),dto.getPageSize()); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | if(dto.getProvice()!=null){ |
| | | wrapper.eq("provice",dto.getProvice()); |
| | | } |
| | | if(dto.getCity()!=null){ |
| | | wrapper.eq("city",dto.getCity()); |
| | | } |
| | | if(dto.getCountry()!=null){ |
| | | wrapper.eq("country",dto.getCountry()); |
| | | } |
| | | if(dto.getStationName()!=null){ |
| | | wrapper.eq("station_name",dto.getStationName()); |
| | | } |
| | | List<StationInf> list=mapper.selectList(wrapper); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询机房"); |
| | | //获取电压等级(下拉) |
| | | public Response getStationTypeByUid(Integer uid) { |
| | | List<String> list=mapper.getStationTypeByUid(uid); |
| | | return new Response().setII(1,list.size()>0,list,"获取电压等级(下拉)"); |
| | | } |
| | | |
| | | /*public List<StationInf> getAllWithFields(Integer userId, String... fields) { |
| | | QueryWrapper<StationInf> query = Wrappers.query(); |
| | | StringBuilder fieldsStr = new StringBuilder(); |
| | | //对fields进行拼接,拼接为select |
| | | for(int i=0;i<fields.length;i++) { |
| | | if(i==fields.length-1) { |
| | | fieldsStr.append(fields[i]); |
| | | }else { |
| | | fieldsStr.append(fields[i]).append(","); |
| | | } |
| | | } |
| | | query.select(fieldsStr.toString()); |
| | | |
| | | return mapper.selectList(query); |
| | | |
| | | }*/ |
| | | //站点信息统计 |
| | | public Response getStationStatistic(StationStic stic) { |
| | | PageHelper.startPage(stic.getPageNum(),stic.getPageSize()); |
| | | List<StationInf> list=mapper.getStationStatistic(stic); |
| | | PageInfo<StationInf> pageInfo=new PageInfo<>(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"站点信息统计"); |
| | | } |
| | | //获取机房信息 |
| | | public StationInf getStationInfById(Integer stationId) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("station_id",stationId); |
| | | wrapper.last("limit 1"); |
| | | StationInf sinf=mapper.selectOne(wrapper); |
| | | //获取机房,电源,电池组变更记录 |
| | | List<StationInfChange> sinfChangeList=changeService.getSinfChange(sinf.getStationId()); |
| | | sinf.setSinfChangeList(sinfChangeList); |
| | | return sinf; |
| | | } |
| | | |
| | | public List<StationInf> getListByUserId(Integer userId) { |
| | | return mapper.getListByUserId(userId); |
| | | } |
| | | } |