| | |
| | | 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; |
| | | |
| | | |
| | | //查询所有区域信息 |
| | |
| | | //获取上一级信息 |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |