| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.whyc.mapper.AreaUserMapper; |
| | | import com.whyc.mapper.UserInfMapper; |
| | | import com.whyc.pojo.db_area.AreaUser; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public class AreaUserService { |
| | | @Autowired(required = false) |
| | | private AreaUserMapper mapper; |
| | | |
| | | @Autowired(required = false) |
| | | private UserInfMapper userInfMapper; |
| | | |
| | | |
| | | //获取用户所管理的区域 |
| | |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return areaList; |
| | | } |
| | | //验证区域是否被用户管理 |
| | | public List<AreaUser> getAreaUser(Integer areaId) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("area_id",areaId); |
| | | List<AreaUser> list=mapper.selectList(wrapper); |
| | | return list; |
| | | } |
| | | //改区域管理员(添加新的记录) |
| | | public void insertArea(Integer id, String uname) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("uid","uname"); |
| | | wrapper.eq("uname",uname); |
| | | UserInf uinf=userInfMapper.selectOne(wrapper); |
| | | AreaUser areaUser=new AreaUser(); |
| | | areaUser.setUname(uname); |
| | | areaUser.setAreaId(id); |
| | | areaUser.setUid(uinf.getUid()); |
| | | mapper.insert(areaUser); |
| | | } |
| | | //获取区域对应的用户名 |
| | | public List<String> getUserNameByAreaIds(List areaList) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("distinct uid","uname"); |
| | | wrapper.in("area_id",areaList); |
| | | List<AreaUser> list=mapper.selectList(wrapper); |
| | | List unameList=list.stream().map(AreaUser::getUname) // 提取用户名 |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return unameList; |
| | | } |
| | | //获取区域对应的用户对象(去除自己) |
| | | public List getUinfByAreaIds(List areaList) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("distinct uid","uname"); |
| | | wrapper.in("area_id",areaList); |
| | | List<AreaUser> list=mapper.selectList(wrapper); |
| | | return list; |
| | | } |
| | | //删除旧的区域对应关系 |
| | | public void delteAreaUser(Integer id) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("area_id",id); |
| | | mapper.delete(wrapper); |
| | | } |
| | | //将新的插入 |
| | | public void insertAreaUser(Integer id, List<AreaUser> areaUserList) { |
| | | if(areaUserList!=null){ |
| | | for ( AreaUser areauser:areaUserList) { |
| | | areauser.setAreaId(id); |
| | | } |
| | | mapper.insertBatchSomeColumn(areaUserList); |
| | | } |
| | | } |
| | | //通过区域id查询所有的用户 |
| | | public List selectUidByAreaId(List areaList) { |
| | | QueryWrapper uinfWrapper=new QueryWrapper(); |
| | | uinfWrapper.select("distinct uid"); |
| | | uinfWrapper.in("area_id",areaList); |
| | | List<AreaUser> list=mapper.selectList(uinfWrapper); |
| | | List uList=list.stream().map(AreaUser::getUid) // 提取用户名 |
| | | .collect(Collectors.toList()); // 转换为列表*/ |
| | | return uList; |
| | | } |
| | | } |