lxw
2022-09-20 867183699202225af1aff812a2111f3b821f1e11
删除台站
3个文件已修改
67 ■■■■ 已修改文件
src/main/java/com/whyc/mapper/StationInfoMapper.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/StationInfoService.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/StationInfoMapper.xml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/StationInfoMapper.java
@@ -2,9 +2,20 @@
import com.whyc.pojo.StationInfo;
import java.util.List;
public interface StationInfoMapper extends CustomMapper<StationInfo>{
    //查询出最大的台站id
    Integer selectMaxId();
    //根据机房名称当前机房的机房id
    Integer selectIdByName(String stationName);
    //找出根节点是stationName1的所有机房id
    List<Integer> selectIdByName1(String stationName1);
    //找出根节点是stationName1,stationName2的所有机房id
    List<Integer> selectIdByName2(String stationName1, String stationName2);
    List<Integer> selectIdByName3(String stationName1, String stationName2, String stationName3);
}
src/main/java/com/whyc/service/StationInfoService.java
@@ -217,33 +217,48 @@
    @Transactional
    public Response deleteStation(String stationName1, String stationName2, String stationName3) {
        String stationName="";
        UpdateWrapper wrapper=new UpdateWrapper();
        int stationFlag=0;
        if(stationName1!=null&&!stationName1.isEmpty()){
            stationName=stationName+stationName1;
            stationFlag=1;
        }
        if(stationName2!=null&&!stationName2.isEmpty()){
            stationName=stationName+"-"+stationName2;
            stationFlag=2;
        }
        if(stationName3!=null&&!stationName3.isEmpty()){
            stationName=stationName+"-"+stationName3;
            stationFlag=3;
        }
        wrapper.eq("station_name",stationName);
        //1.先查出机房的id
        Integer stationId=mapper.selectIdByName(stationName);
        if(stationId==null){
        List<Integer> idStations=new ArrayList<>();
        if(stationFlag==1){
            //找出根节点是stationName1的所有机房id
            idStations=mapper.selectIdByName1(stationName1);
        }
        if(stationFlag==2){
            //找出根节点是stationName1,stationName2的所有机房id
            idStations=mapper.selectIdByName2(stationName1,stationName2);
        }
        if(stationFlag==3){
            //找出根节点是stationName1,stationName2,stationName3的所有机房id
           idStations=mapper.selectIdByName3(stationName1,stationName2,stationName3);
        }
        if(idStations!=null&&idStations.size()>0){
            for (int stationId:idStations) {
                //3.删除所有文件数据
                dataMapper.deleteDataAndInfoByStationId(stationId);
                //4.删除所有文件参数
                paramMapper.deleteParamByStationId(stationId);
                //最终删除基站
                UpdateWrapper wrapper=new UpdateWrapper();
                wrapper.eq("station_id",stationId);
                wrapper.eq("station_name",stationName);
                mapper.delete(wrapper);
            }
            return new Response().set(1,true,"删除成功");
        }else{
            return new Response().set(1,false,"机房不存在");
        }else if(stationId==0){
            //最终删除基站
            mapper.delete(wrapper);
        }else {
            //3.删除所有文件数据
            dataMapper.deleteDataAndInfoByStationId(stationId);
            //4.删除所有文件参数
            paramMapper.deleteParamByStationId(stationId);
            //最终删除基站
            mapper.delete(wrapper);
        }
        return new Response().set(1,true,"删除成功");
    }
    //移除台站下文件(单个文件)
    @Transactional
src/main/resources/mapper/StationInfoMapper.xml
@@ -15,4 +15,13 @@
    <select id="selectIdByName" resultType="java.lang.Integer">
        select ifnull(station_id,0) from db_res_meter.tb_station_info where station_name=#{stationName} limit 1
    </select>
    <select id="selectIdByName2" resultType="java.lang.Integer">
        select distinct station_id from db_res_meter.tb_station_info where station_name1=#{stationName1} and station_name2=#{stationName2}
    </select>
    <select id="selectIdByName3" resultType="java.lang.Integer">
        select distinct station_id from db_res_meter.tb_station_info where station_name1=#{stationName1} and station_name2=#{stationName2} and station_name3=#{stationName3}
    </select>
    <select id="selectIdByName1" resultType="java.lang.Integer">
        select distinct station_id from db_res_meter.tb_station_info where station_name1=#{stationName1}
    </select>
</mapper>