whyclxw
2024-11-26 bdaab68df16cb59903dfc296bfab00b65f5695b8
添加区域对应用户信息
2个文件已修改
97 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/AreaInfController.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/AreaInfService.java 87 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/AreaInfController.java
@@ -40,5 +40,15 @@
    public Response updateArea(@RequestParam(required = false) Integer id,@RequestParam String areaName,@RequestParam(required = false) String areaUname,@RequestParam(required = false) String areaDescript){
        return service.updateArea(id,areaName,areaUname,areaDescript);
    }
    @ApiOperation(value = "查询所有区域下所有用户信息")
    @GetMapping("getUinfById")
    public Response getUinfById(@RequestParam Integer id){
        return service.getUinfById(id);
    }
    @ApiOperation(value = "查询所有区域下所有锁信息")
    @GetMapping("getLinfById")
    public Response getLinfById(@RequestParam Integer id){
        return service.getLinfById(id);
    }
}
src/main/java/com/whyc/service/AreaInfService.java
@@ -4,17 +4,29 @@
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.whyc.dto.Response;
import com.whyc.mapper.AreaInfMapper;
import com.whyc.mapper.LockInfMapper;
import com.whyc.mapper.UserInfMapper;
import com.whyc.pojo.db_area.AreaInf;
import com.whyc.pojo.db_area.LockInf;
import com.whyc.pojo.db_user.UserInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
public class AreaInfService {
    @Autowired(required = false)
    private AreaInfMapper mapper;
    @Autowired(required = false)
    private LockInfMapper linfMapper;
    @Autowired(required = false)
    private UserInfMapper uInfMapper;
    //查询所有区域信息
@@ -61,10 +73,11 @@
        //获取上一级信息
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("parent_id",id);
        wrapper.last("limit 1");
        AreaInf painf=mapper.selectOne(wrapper);
        if(painf!=null){
            delAll(painf.getId());
        List<AreaInf> list=mapper.selectList(wrapper);
        if(list!=null){
            for (AreaInf painf:list) {
                delAll(painf.getId());
            }
        }
        UpdateWrapper wrapper1=new UpdateWrapper();
        wrapper1.eq("id",id);
@@ -90,15 +103,71 @@
    public void updateAll(Integer id, String newPath) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("parent_id",id);
        wrapper.last("limit 1");
        AreaInf painf=mapper.selectOne(wrapper);
        if(painf!=null){
            String path=newPath+"_"+painf.getAreaName();
            updateAll(painf.getId(),path);
        List<AreaInf> list=mapper.selectList(wrapper);
        if(list!=null){
            for (AreaInf painf:list) {
                String path=newPath+"_"+painf.getAreaName();
                updateAll(painf.getId(),path);
            }
        }
        UpdateWrapper wrapper2=new UpdateWrapper();
        wrapper2.set("area_path",newPath);
        wrapper2.eq("id",id);
        mapper.update(null,wrapper2);
    }
    //查询所有区域下所有锁信息
    public Response getLinfById(Integer id) {
        //获取获取id下所有的区域id
        List areaList=new ArrayList();
        areaList.add(id);
        getAllAreaId(id,areaList);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.in("area_id",areaList);
        List<LockInf> list=linfMapper.selectList(wrapper);
        return new Response().setII(1,list!=null,list,"查询所有区域下所有锁信息");
    }
    //获取获取id下所有的区域id
    private void getAllAreaId(Integer id,List areaList) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("parent_id",id);
        List<AreaInf> list=mapper.selectList(wrapper);
        if(list!=null){
            for (AreaInf painf:list) {
                areaList.add(painf.getId());
                getAllAreaId(painf.getId(),areaList);
            }
        }
    }
    //查询所有区域下所有用户信息
    public Response getUinfById(Integer id) {
        //获取获取id下所有的区域id
        List uinfList=new ArrayList();
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("id",id);
        wrapper.last("limit 1");
        AreaInf ainf=mapper.selectOne(wrapper);
        if(ainf!=null){
            uinfList.add(ainf.getAreaUname());
        }
        getAllUinfId(id,uinfList);
        QueryWrapper wrapper1=new QueryWrapper();
        wrapper1.select("uid","uname","CREATE_TIME");
        wrapper1.in("uname",uinfList);
        List<UserInf> list=uInfMapper.selectList(wrapper1);
        return new Response().setII(1,list!=null,list,"查询所有区域下所有用户信息");
    }
    //获取获取id下所有的区域用户名
    private void getAllUinfId(Integer id,List uinfList) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("parent_id",id);
        List<AreaInf> list=mapper.selectList(wrapper);
        if(list!=null){
            for (AreaInf painf:list) {
                uinfList.add(painf.getAreaUname());
                getAllUinfId(painf.getId(),uinfList);
            }
        }
    }
}