| | |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | * @param user |
| | | */ |
| | | public void updateGridBind(User user) { |
| | | // 先删除原有区域的绑定 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).like("police_user_id",user.getId()); |
| | | // 删除掉之前已绑定的 |
| | | List<PoliceAffairsGridEntity> list = SpringUtil.getBean(IPoliceAffairsGridService.class).list(queryWrapper); |
| | | // 遍历 |
| | | for (PoliceAffairsGridEntity policeAffairsGridEntity : list) { |
| | | List<String> arrayList = new ArrayList<>(Arrays.asList(policeAffairsGridEntity.getPoliceUserId().split(","))); |
| | | arrayList.remove(user.getId().toString()); |
| | | // 更新 |
| | | policeAffairsGridEntity.setPoliceUserId(String.join(",",arrayList)); |
| | | // 解决更新报错 |
| | | policeAffairsGridEntity.setGeom(null); |
| | | SpringUtil.getBean(IPoliceAffairsGridService.class).updateById(policeAffairsGridEntity); |
| | | } |
| | | // 判断机构类型 |
| | | List<String> deptIds = Arrays.asList(user.getDeptId().split(",")); |
| | | List<String> deptIds = new ArrayList<>(Arrays.asList(user.getDeptId().split(","))); |
| | | for (String deptId : deptIds) { |
| | | // 查询对应的机构 |
| | | Dept dept = SpringUtil.getBean(IDeptService.class).getById(deptId); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public IPage<User> selectUserPage(IPage<User> page, User user, Long deptId, String tenantId) { |
| | | if (null == deptId && !AuthUtil.isAdministrator()) { |
| | | deptId = Long.parseLong(AuthUtil.getDeptId()); |
| | | public IPage<User> selectUserPage(IPage<User> page, User user, String deptId, String tenantId) { |
| | | if (Strings.isBlank(deptId) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()) { |
| | | deptId = AuthUtil.getDeptId(); |
| | | } |
| | | List<Long> deptIdList = SysCache.getDeptChildIds(deptId); |
| | | return page.setRecords(baseMapper.selectUserPage(page, user, deptIdList, tenantId)); |
| | |
| | | if (Func.contains(Func.toLongArray(userIds), AuthUtil.getUserId())) { |
| | | throw new ServiceException("不能删除本账号!"); |
| | | } |
| | | return deleteLogic(Func.toLongList(userIds)); |
| | | boolean deleteLogic = deleteLogic(Func.toLongList(userIds)); |
| | | if (deleteLogic){ |
| | | // 删除警格绑定 |
| | | removePoliceGridBind(userIds); |
| | | } |
| | | return deleteLogic; |
| | | } |
| | | |
| | | /** |
| | | * 删除警格绑定 |
| | | * @param userIds |
| | | */ |
| | | public void removePoliceGridBind(String userIds) { |
| | | List<String> userIdList = new ArrayList<>(Arrays.asList(userIds.split(","))); |
| | | for (String userId : userIdList) { |
| | | // 先删除原有区域的绑定 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).like("police_user_id",userId); |
| | | // 删除掉之前已绑定的 |
| | | List<PoliceAffairsGridEntity> list = SpringUtil.getBean(IPoliceAffairsGridService.class).list(queryWrapper); |
| | | if (list.size()>0) { |
| | | // 遍历 |
| | | for (PoliceAffairsGridEntity policeAffairsGridEntity : list) { |
| | | List<String> arrayList = new ArrayList<>(Arrays.asList(policeAffairsGridEntity.getPoliceUserId().split(","))); |
| | | arrayList.remove(userId); |
| | | // 更新 |
| | | policeAffairsGridEntity.setPoliceUserId(String.join(",", arrayList)); |
| | | // 解决更新报错 |
| | | policeAffairsGridEntity.setGeom(null); |
| | | SpringUtil.getBean(IPoliceAffairsGridService.class).updateById(policeAffairsGridEntity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | return baseMapper.getUserInfoByDistrictId(districtId, building); |
| | | } |
| | | |
| | | @Override |
| | | public List<User> getUserInfoByDistrictIds(String districtIds) { |
| | | List<String> list = JSON.parseArray(districtIds).toJavaList(String.class); |
| | | return baseMapper.getUserInfoByDistrictIds(list); |
| | | } |
| | | |
| | | /** |
| | | * 处理漏绑定的user_dept |
| | | */ |
| | |
| | | // 判断角色 |
| | | if (!userInfo.getRoleId().contains("1727864411451359233")){ |
| | | userInfo.setRoleId(userInfo.getRoleId() + ",1727864411451359233"); |
| | | // 更新 |
| | | updateById(userInfo); |
| | | // 更新社区民警绑定信息 |
| | | updateCommunityInfo(userExcel,userInfo); |
| | | } |
| | | // 更新机构 |
| | | setDeptId(userInfo,userExcel); |
| | | // 更新 |
| | | updateById(userInfo); |
| | | // 更新用户机构绑定 |
| | | submitUserDept(userInfo); |
| | | // 更新社区民警绑定信息 |
| | | updateGridBind(userInfo); |
| | | }else { |
| | | // 插入用户角色 |
| | | User user = new User(); |
| | |
| | | user.setRealName(userExcel.getRealName()); |
| | | user.setPhone(userExcel.getPhone()); |
| | | user.setAccount(userExcel.getPhone()); |
| | | // 查询机构 |
| | | QueryWrapper<Dept> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).eq("dept_name",userExcel.getPoliceStationName()); |
| | | Dept dept = SpringUtil.getBean(IDeptService.class).getOne(queryWrapper); |
| | | if (null!=dept){ |
| | | user.setDeptId(dept.getId().toString()); |
| | | } |
| | | // 更新机构 |
| | | setDeptId(user,userExcel); |
| | | // 设置初始密码 |
| | | user.setPassword("123456"); |
| | | // 保存 |
| | | submit(user); |
| | | // 更新用户机构绑定 |
| | | submitUserDept(user); |
| | | // 更新社区民警绑定信息 |
| | | updateCommunityInfo(userExcel,user); |
| | | updateGridBind(user); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置机构 |
| | | */ |
| | | public void setDeptId(User user,PoliceUserExcel userExcel) { |
| | | // 查询机构 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0) |
| | | .eq("community_code",userExcel.getCommunityCode()) |
| | | .eq("pcs_name",userExcel.getPoliceStationName()); |
| | | PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridService.getOne(queryWrapper); |
| | | if (null!=policeAffairsGridEntity){ |
| | | // 查询对应绑定的机构 |
| | | QueryWrapper<Dept> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0) |
| | | .eq("dept_nature",1) |
| | | .eq("region_code",policeAffairsGridEntity.getJwGridCode()); |
| | | Dept dept = SpringUtil.getBean(IDeptService.class).getOne(wrapper); |
| | | if (null!=dept){ |
| | | if (null!=user.getId()){ |
| | | DeptNotHandle(user, dept); |
| | | }else { |
| | | user.setDeptId(dept.getId().toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 机构不为空时处理 |
| | | * @param user |
| | | * @param dept |
| | | */ |
| | | public void DeptNotHandle(User user, Dept dept) { |
| | | // 更新设置机构 |
| | | if (!Strings.isBlank(user.getDeptId())){ |
| | | // 查询对应的派出所(去掉) |
| | | Dept deptPcs = SpringUtil.getBean(IDeptService.class).getDeptByDeptIds(user.getDeptId()); |
| | | if (null!=deptPcs) { |
| | | // 如果存在需要去掉派出所的机构id |
| | | List<String> list = new ArrayList<>(Arrays.asList(user.getDeptId().split(","))); |
| | | // 先删除派出所对应的机构ID |
| | | if (list.contains(deptPcs.getId().toString())){ |
| | | list.remove(deptPcs.getId().toString()); |
| | | user.setDeptId(String.join(",",list)); |
| | | } |
| | | // 删完后可能就没了 |
| | | if (!Strings.isBlank(user.getDeptId())) { |
| | | if (!user.getDeptId().contains(dept.getId().toString())) { |
| | | user.setDeptId(user.getDeptId() + "," + dept.getId()); |
| | | } |
| | | }else { |
| | | // 删完后的 |
| | | user.setDeptId(dept.getId().toString()); |
| | | } |
| | | }else { |
| | | if (!user.getDeptId().contains(dept.getId().toString())) { |
| | | user.setDeptId(user.getDeptId() + "," + dept.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |