whyclxw
2025-05-15 96510a549bfb313920bf297b28089c4cf57f0146
src/main/java/com/whyc/service/StationInfService.java
@@ -1,10 +1,18 @@
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.Response;
import com.whyc.dto.Station.Provice;
import com.whyc.dto.StationDto;
import com.whyc.mapper.BaojigroupMapper;
import com.whyc.mapper.StationInfMapper;
import com.whyc.pojo.plus_inf.LockInf;
import com.whyc.pojo.plus_inf.StationInf;
import com.whyc.pojo.plus_user.Baojigroup;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -15,6 +23,12 @@
public class StationInfService {
    @Autowired(required = false)
    private StationInfMapper mapper;
    @Autowired
    private LockInfService linfService;
    @Autowired(required = false)
    private BaojigroupMapper groupMapper;
    //获取左侧列表
    public Response getLeftStation(int uid) {
@@ -46,4 +60,100 @@
        List<LockInf> list=mapper.getLockByUid(uid,stationName1,stationName2,stationName3,stationName4);
        return new Response().setII(1,list.size()>0,list,"获取省市区县机房站点下的锁");
    }
    //添加机房
    public Response addStatiaon(StationInf addsinf) {
        //判断添加锁的时候机房是不是新机房
        String stationName=addsinf.getStationName1()+"_"+addsinf.getStationName2()+"_"+addsinf.getStationName3()+"_"+addsinf.getStationName4();
        //判断机房是否存在
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("station_name",stationName);
        wrapper.last("limit 1");
        StationInf sinf=mapper.selectOne(wrapper);
        int stationId=0;
        int lockId=0;
        if(sinf!=null){
            return new Response().set(1,false,"机房已存在");
        }else {
            //获取当前最大的机房id
            Integer maxStationNum=mapper.getMaxStationNum();
            if(maxStationNum==0){//数据库中没有站点
                stationId=40000001;
            }else{
                //获取对应的机房id
                stationId=mapper.getStaitonIdByNum(maxStationNum);
                stationId+=1;
            }
            StationInf newSinf=new StationInf();
            newSinf.setStationId(stationId);
            newSinf.setStationName(stationName);
            newSinf.setStationNum(maxStationNum+1);
            newSinf.setStationName1(addsinf.getStationName1());
            newSinf.setStationName2(addsinf.getStationName2());
            newSinf.setStationName3(addsinf.getStationName3());
            newSinf.setStationName4(addsinf.getStationName4());
            mapper.insert(newSinf);
            linfService.insertInbaoji(stationId,lockId);
            return new Response().set(1,true,"添加机房");
        }
    }
    //删除机房
    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.getStationName1()!=null){
            wrapper.set("station_name1",sinf.getStationName1());
        }
        if(sinf.getStationName2()!=null){
            wrapper.set("station_name2",sinf.getStationName2());
        }
        if(sinf.getStationName3()!=null){
            wrapper.set("station_name3",sinf.getStationName3());
        }
        if(sinf.getStationName4()!=null){
            wrapper.set("station_name4",sinf.getStationName4());
        }
        String stationName=sinf.getStationName1()+"_"+sinf.getStationName2()+"_"+sinf.getStationName3()+"_"+sinf.getStationName4();
        wrapper.set("station_name",stationName);
        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.getStationName1()!=null){
            wrapper.eq("station_name1",dto.getStationName1());
        }
        if(dto.getStationName2()!=null){
            wrapper.eq("station_name2",dto.getStationName2());
        }
        if(dto.getStationName3()!=null){
            wrapper.eq("station_name3",dto.getStationName3());
        }
        if(dto.getStationName4()!=null){
            wrapper.eq("station_name4",dto.getStationName4());
        }
        List<StationInf> list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"查询机房");
    }
    //根据stationid和包机组id查询机房名和包机组名
    public Response getNamebyId(Integer stationId, Integer baojiId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("station_id",stationId);
        wrapper.last("limit 1");
        StationInf sinf=mapper.selectOne(wrapper);
        QueryWrapper wrapper1=new QueryWrapper();
        wrapper1.eq("id",baojiId);
        wrapper1.last("limit 1");
        Baojigroup baoji=groupMapper.selectOne(wrapper1);
        return new Response().setIII(1,true,sinf,baoji,"根据stationid和包机组id查询机房名和包机组名");
    }
}