| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.flowable.idm.engine.impl.persistence.entity.UserEntity; |
| | | import org.springblade.common.param.CommonParamSet; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.modules.grid.entity.GridEntity; |
| | | import org.springblade.modules.grid.entity.GridmanEntity; |
| | | import org.springblade.modules.grid.excel.GridmanExcel; |
| | |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.grid.service.IGridmanService; |
| | | import org.springblade.modules.grid.vo.GridmanVO; |
| | | import org.springblade.modules.system.entity.Dept; |
| | | import org.springblade.modules.system.entity.Region; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springblade.modules.system.service.IRegionService; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private IGridService gridService; |
| | | |
| | | @Autowired |
| | | private IRegionService regionService; |
| | | |
| | | @Override |
| | | public IPage<GridmanVO> selectGridmanPage(IPage<GridmanVO> page, GridmanVO gridman) { |
| | | return page.setRecords(baseMapper.selectGridmanPage(page, gridman)); |
| | | CommonParamSet commonParamSet = new CommonParamSet<>().invoke(GridmanVO.class, gridman); |
| | | return page.setRecords(baseMapper.selectGridmanPage(page, gridman, commonParamSet.getRegionChildCodesList(), commonParamSet.getIsAdministrator())); |
| | | } |
| | | |
| | | /** |
| | | * 网格员表 自定义新增或修改 |
| | | * |
| | | * @param gridman |
| | | * @return |
| | | */ |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateGridman(GridmanEntity gridman) { |
| | | boolean flag = false; |
| | | // 查询网格id |
| | | IGridService bean = SpringUtil.getBean(IGridService.class); |
| | | GridEntity gridEntity = bean.getOne(Wrappers.<GridEntity>lambdaQuery().eq(GridEntity::getGridCode, gridman.getGridCode())); |
| | | // 修改 |
| | | if (null!=gridman.getId()) { |
| | | if (null != gridman.getId()) { |
| | | // 更新网格id |
| | | gridman.setGridId(gridEntity.getId()); |
| | | // 更新网格员信息 |
| | | flag = updateById(gridman); |
| | | }else { |
| | | } else { |
| | | // 新增 |
| | | // 先判断用户表中是否已存在该用户,如果已存在则不新增,需要更新角色 |
| | | QueryWrapper<User> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted", 0).eq("account", gridman.getMobile()); |
| | | List<User> list = userService.list(wrapper); |
| | | // 更新用户,查询是否需要更新角色 |
| | | gridman.setGridId(gridEntity.getId()); |
| | | if (list.size() > 0) { |
| | | // 默认取出第一个 |
| | | User user = list.get(0); |
| | |
| | | } |
| | | //插入网格员信息 |
| | | gridman.setUserId(user.getId()); |
| | | flag = save(gridman); |
| | | //匹配 |
| | | QueryWrapper<GridmanEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0) |
| | | .eq("grid_id", gridman.getGridId()) |
| | | .eq("user_id", gridman.getUserId()); |
| | | GridmanEntity one = getOne(queryWrapper); |
| | | if (null == one) { |
| | | flag = save(gridman); |
| | | } |
| | | } else { |
| | | saveUser(gridman); |
| | | // 插入网格员信息 |
| | | flag = save(gridman); |
| | | //匹配 |
| | | QueryWrapper<GridmanEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0) |
| | | .eq("grid_id", gridman.getGridId()) |
| | | .eq("user_id", gridman.getUserId()); |
| | | GridmanEntity one = getOne(queryWrapper); |
| | | if (null == one) { |
| | | flag = save(gridman); |
| | | } |
| | | } |
| | | } |
| | | // 返回 |
| | |
| | | |
| | | /** |
| | | * 用户新增 |
| | | * |
| | | * @param gridman |
| | | */ |
| | | public void saveUser(GridmanEntity gridman) { |
| | |
| | | |
| | | /** |
| | | * 网格员导入 |
| | | * |
| | | * @param data |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importGridman(List<GridmanExcel> data, Boolean isCovered) { |
| | | // 遍历 |
| | | for (GridmanExcel gridmanExcel : data) { |
| | | GridmanEntity gridmanEntity = Objects.requireNonNull(BeanUtil.copy(gridmanExcel, GridmanEntity.class)); |
| | | // 先查询当前网格社区对应的机构id |
| | | QueryWrapper<Region> regionWrapper = new QueryWrapper<>(); |
| | | regionWrapper.eq("name",gridmanExcel.getCommunityName()); |
| | | Region region = regionService.getOne(regionWrapper); |
| | | // 通过社区名称和网格名称获取网格id |
| | | QueryWrapper<GridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0) |
| | | .eq("community_code",region.getCode()) |
| | | .eq("grid_name",gridmanExcel.getGridName()); |
| | | GridEntity gridEntity = gridService.getOne(queryWrapper); |
| | | // 设置网格id |
| | | gridmanEntity.setGridId(gridEntity.getId()); |
| | | // 通过手机号查询网格员id |
| | | QueryWrapper<GridmanEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).eq("mobile",gridmanEntity.getMobile()); |
| | | GridmanEntity one = getOne(wrapper); |
| | | if (one!=null){ |
| | | gridmanEntity.setId(one.getId()); |
| | | // 先查询是否有对应的用户 |
| | | List<User> userList = userService.getUserListByPhoneOrAccount(gridmanExcel.getMobile()); |
| | | if (userList.size()>0){ |
| | | User user = userList.get(0); |
| | | // 判断角色是否包好网格员的角色,如果没有则加入网格员的角色,有则不更改 |
| | | if (!user.getRoleId().contains("1717429261910528001")) { |
| | | // 更新角色 |
| | | user.setRoleId(user.getRoleId() + "," + "1717429261910528001"); |
| | | // 更新机构 |
| | | setDeptId(gridmanExcel,user); |
| | | // 更新用户信息 |
| | | userService.updateById(user); |
| | | // 更新网格员绑定 |
| | | updateGridmanBind(gridmanExcel,user); |
| | | } |
| | | }else { |
| | | // 创建用户 |
| | | User user = new User(); |
| | | user.setTenantId("000000"); |
| | | user.setUserType(1); |
| | | user.setRoleId("1717429261910528001"); |
| | | user.setName(gridmanExcel.getGridmanName()); |
| | | user.setRealName(gridmanExcel.getGridmanName()); |
| | | user.setPhone(gridmanExcel.getMobile()); |
| | | user.setAccount(gridmanExcel.getMobile()); |
| | | // 更新机构 |
| | | setDeptId(gridmanExcel,user); |
| | | // 设置默认密码 |
| | | user.setPassword("123456"); |
| | | // 保存 |
| | | userService.submit(user); |
| | | // 更新网格员绑定 |
| | | updateGridmanBind(gridmanExcel,user); |
| | | } |
| | | // 插入网格员 |
| | | saveOrUpdateGridman(gridmanEntity); |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新网格员绑定 |
| | | * @param gridmanExcel |
| | | * @param user |
| | | */ |
| | | public void updateGridmanBind(GridmanExcel gridmanExcel, User user) { |
| | | // 保存更新网格员信息 |
| | | GridmanEntity gridmanEntity = Objects.requireNonNull(BeanUtil.copy(gridmanExcel, GridmanEntity.class)); |
| | | // 通过社区名称和网格名称获取网格id |
| | | QueryWrapper<GridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0) |
| | | .eq("grid_code", gridmanExcel.getGridCode()); |
| | | GridEntity gridEntity = gridService.getOne(queryWrapper); |
| | | // 设置网格id |
| | | gridmanEntity.setGridId(gridEntity.getId()); |
| | | gridmanEntity.setUserId(user.getId()); |
| | | // 插入网格员 |
| | | // 判断是否已存,已存在则更新,否则插入 |
| | | QueryWrapper<GridmanEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).eq("user_id",user.getId()).eq("grid_code",gridmanExcel.getGridCode()); |
| | | GridmanEntity entity = getOne(wrapper); |
| | | if (null!=entity){ |
| | | gridmanEntity.setId(entity.getId()); |
| | | updateById(gridmanEntity); |
| | | }else { |
| | | save(gridmanEntity); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新机构 |
| | | * @param gridmanExcel |
| | | * @param user |
| | | */ |
| | | public void setDeptId(GridmanExcel gridmanExcel, User user) { |
| | | // 通过社区编号查询对应的机构id |
| | | Region region = SpringUtil.getBean(IRegionService.class).getById(gridmanExcel.getCommunityCode()); |
| | | // 查询社区对应的机构 |
| | | QueryWrapper<Dept> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).eq("dept_name",region.getName()); |
| | | Dept dept = SpringUtil.getBean(IDeptService.class).getOne(wrapper); |
| | | // 查询网格对应的机构 |
| | | QueryWrapper<Dept> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0). |
| | | eq("parent_id",dept.getId()). |
| | | eq("dept_name",gridmanExcel.getGridName()); |
| | | System.out.println("网格名称 = " + gridmanExcel.getGridName()); |
| | | Dept deptGrid = SpringUtil.getBean(IDeptService.class).getOne(queryWrapper); |
| | | // 设置机构 |
| | | user.setDeptId(deptGrid.getId().toString()); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public Object getGridStatistics(String code, String roleType) { |
| | | Map<String, Object> objectObjectHashMap = new HashMap<>(); |
| | | if (roleType.equals("1")) { |
| | | Integer gridStatistics = baseMapper.getGridStatistics(code, AuthUtil.getUserId()); |
| | | Integer companyStatistics = baseMapper.getCompanyStatistics(code, AuthUtil.getUserId()); |
| | | List<String> communityCodeList = Func.toStrList(code); |
| | | // 判断 communityCodeList |
| | | if (communityCodeList != null && communityCodeList.size() == 0) { |
| | | return objectObjectHashMap; |
| | | } |
| | | if (roleType.equals("2")) { |
| | | Integer gridStatistics = baseMapper.getGridStatistics(communityCodeList, null, roleType); |
| | | Integer companyStatistics = baseMapper.getCompanyStatistics(communityCodeList, null, roleType); |
| | | Integer ownersCommitteeStatistics = baseMapper.getOwnersCommitteeStatistics(communityCodeList, null, roleType); |
| | | objectObjectHashMap.put("gridStatistics", gridStatistics); |
| | | objectObjectHashMap.put("companyStatistics", companyStatistics); |
| | | objectObjectHashMap.put("ownersStatistics", ownersCommitteeStatistics); |
| | | } else { |
| | | Integer gridStatistics = baseMapper.getGridStatistics(code, AuthUtil.getUserId()); |
| | | Integer companyStatistics = baseMapper.getCompanyStatistics(code, null); |
| | | Integer gridStatistics = baseMapper.getGridStatistics(communityCodeList, AuthUtil.getUserId(), roleType); |
| | | Integer companyStatistics = baseMapper.getCompanyStatistics(communityCodeList, AuthUtil.getUserId(), roleType); |
| | | Integer ownersCommitteeStatistics = baseMapper.getOwnersCommitteeStatistics(communityCodeList, AuthUtil.getUserId(), roleType); |
| | | objectObjectHashMap.put("gridStatistics", gridStatistics); |
| | | objectObjectHashMap.put("companyStatistics", companyStatistics); |
| | | objectObjectHashMap.put("ownersStatistics", ownersCommitteeStatistics); |
| | | |
| | | } |
| | | return objectObjectHashMap; |
| | | } |
| | | |
| | | /** |
| | | * 网格员表 自定义详情 |
| | | */ |
| | | @Override |
| | | public GridmanVO getDetail(GridmanEntity gridman) { |
| | | return baseMapper.getDetail(gridman); |
| | | } |
| | | |
| | | /** |
| | | * 查询网格id |
| | | * |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer getGridIdByUserId(Long userId) { |
| | | return baseMapper.getGridIdByUserId(userId); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserEntity> getGridManByCode(String houseCode) { |
| | | return baseMapper.getGridManByCode(houseCode); |
| | | } |
| | | } |