| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill 庄骞 (smallchill@163.com) |
| | | */ |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.node.TreeStringNode; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.common.utils.AuthUtils; |
| | | import org.springblade.common.utils.NodeTreeUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | import org.springblade.core.tool.node.ForestNodeMerger; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.modules.community.entity.CommunityEntity; |
| | | import org.springblade.modules.community.service.ICommunityService; |
| | | import org.springblade.modules.grid.entity.GridEntity; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.police.entity.PoliceAffairsGridEntity; |
| | | import org.springblade.modules.police.service.IPoliceAffairsGridService; |
| | | import org.springblade.modules.property.entity.PropertyCompanyEntity; |
| | | import org.springblade.modules.property.service.IPropertyCompanyService; |
| | | import org.springblade.modules.system.entity.Dept; |
| | | import org.springblade.modules.system.entity.Region; |
| | | import org.springblade.modules.system.mapper.DeptMapper; |
| | | import org.springblade.modules.system.node.DeptUserTreeNode; |
| | | import org.springblade.modules.system.node.TreeNode; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springblade.modules.system.service.IRegionService; |
| | | import org.springblade.modules.system.vo.DeptDetailVO; |
| | | import org.springblade.modules.system.vo.DeptVO; |
| | | import org.springblade.modules.system.wrapper.DeptWrapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService { |
| | | private static final String TENANT_ID = "tenantId"; |
| | | private static final String PARENT_ID = "parentId"; |
| | | |
| | | @Autowired |
| | | private IPropertyCompanyService propertyCompanyService; |
| | | |
| | | @Autowired |
| | | private IRegionService regionService; |
| | |
| | | parentId = 0L; |
| | | } |
| | | // 判断数据权限控制,非超管角色只可看到本级及以下数据 |
| | | if (Func.toLong(parentId) == 0L && !AuthUtil.isAdministrator()) { |
| | | if (Func.toLong(parentId) == 0L && !AuthUtils.isAdministratorOrAdmin(AuthUtil.getUserRole())) { |
| | | Long deptId = Func.firstLong(AuthUtil.getDeptId()); |
| | | Dept dept = SysCache.getDept(deptId); |
| | | if (dept.getParentId() != 0) { |
| | | if (dept != null && dept.getParentId() != 0) { |
| | | parentId = dept.getParentId(); |
| | | } |
| | | List<DeptVO> deptVOS = baseMapper.lazyList(tenantId, parentId, param); |
| | |
| | | if (Func.toLong(parentId) == 0L && !AuthUtil.isAdmin()) { |
| | | Long deptId = Func.firstLong(AuthUtil.getDeptId()); |
| | | Dept dept = SysCache.getDept(deptId); |
| | | if (dept.getParentId() != 0) { |
| | | if (dept != null && dept.getParentId() != 0) { |
| | | parentId = dept.getParentId(); |
| | | } |
| | | List<DeptVO> merge = ForestNodeMerger.merge(baseMapper.lazyTree(tenantId, parentId)); |
| | |
| | | throw new ServiceException("请先删除子节点!"); |
| | | } |
| | | List<Long> longs = Func.toLongList(ids); |
| | | // 遍历 |
| | | for (Long id : longs) { |
| | | // 查询当前机构信息 |
| | | DeptVO dept = baseMapper.getDeptById(id); |
| | | // 如果父机构为物业公司 |
| | | if (dept.getParentName().equals("物业公司")) { |
| | | // 删除 |
| | | propertyCompanyService.remove(Wrappers.<PropertyCompanyEntity>update().lambda().eq(PropertyCompanyEntity::getDeptId, id)); |
| | | } |
| | | } |
| | | return removeByIds(longs); |
| | | } |
| | | |
| | |
| | | dept.setId(one.getId()); |
| | | flag = updateById(dept); |
| | | } else { |
| | | if (dept.getId() > 0) { |
| | | if (dept.getId() != null && dept.getId() > 0) { |
| | | flag = updateById(dept); |
| | | } else { |
| | | flag = save(dept); |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void savePropertyCompany(Dept dept) { |
| | | // 查询物业公司是否存在 |
| | | QueryWrapper<PropertyCompanyEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted", 0) |
| | | .eq("dept_id", dept.getId()) |
| | | .eq("name", dept.getDeptName()); |
| | | PropertyCompanyEntity propertyCompanyEntity = propertyCompanyService.getOne(wrapper); |
| | | if (null != propertyCompanyEntity) { |
| | | // 修改 |
| | | propertyCompanyEntity.setDeptId(dept.getId()); |
| | | propertyCompanyEntity.setName(dept.getDeptName()); |
| | | // 往物业公司表中插入一条数据 |
| | | propertyCompanyService.updateById(propertyCompanyEntity); |
| | | } else { |
| | | // 新增 |
| | | PropertyCompanyEntity companyEntity = new PropertyCompanyEntity(); |
| | | companyEntity.setDeptId(dept.getId()); |
| | | companyEntity.setName(dept.getDeptName()); |
| | | // 往物业公司表中插入一条数据 |
| | | propertyCompanyService.save(companyEntity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | public Object dataHandle() { |
| | | // 查询所有的社区 |
| | | QueryWrapper<Region> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("district_code","361102").eq("region_level",5); |
| | | queryWrapper.eq("district_code", "361102").eq("region_level", 5); |
| | | List<Region> list = regionService.list(queryWrapper); |
| | | // 遍历 |
| | | for (Region region : list) { |
| | |
| | | QueryWrapper<Dept> deptQueryWrapper = new QueryWrapper<>(); |
| | | deptQueryWrapper.eq("is_deleted", 0).eq("dept_name", region.getTownName()); |
| | | Dept parentDept = getOne(deptQueryWrapper); |
| | | if (null!=parentDept){ |
| | | if (null != parentDept) { |
| | | dept.setParentId(parentDept.getId()); |
| | | dept.setAncestors(parentDept.getAncestors() + "," + parentDept.getId()); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Object dataHandleCommunity() { |
| | | // 查询所有的社区 |
| | | QueryWrapper<Region> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("district_code","361102").eq("region_level",5); |
| | | List<Region> list = regionService.list(queryWrapper); |
| | | // 遍历 |
| | | for (Region region : list) { |
| | | // 查询是否已创建 |
| | | QueryWrapper<CommunityEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted", 0).eq("name", region.getName()); |
| | | CommunityEntity one = SpringUtil.getBean(ICommunityService.class).getOne(wrapper); |
| | | if (null == one) { |
| | | // 新增 |
| | | CommunityEntity communityEntity = new CommunityEntity(); |
| | | communityEntity.setStreetCode(region.getTownCode()); |
| | | communityEntity.setName(region.getName()); |
| | | communityEntity.setCode(region.getCode()); |
| | | // 新增 |
| | | SpringUtil.getBean(ICommunityService.class).save(communityEntity); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Object dataRegionGridCodeBindHandle() { |
| | | // 查询网格对应的机构信息(包含父级机构名称) |
| | | List<DeptVO> deptVOS = baseMapper.getGridDeptAndParentList(); |
| | | //遍历处理 |
| | | for (DeptVO deptVO : deptVOS) { |
| | | GridEntity gridEntity = SpringUtils.getBean(IGridService.class).getGridByNames(deptVO.getDeptName(), deptVO.getParentName()); |
| | | if (null != gridEntity) { |
| | | deptVO.setRegionCode(gridEntity.getGridCode()); |
| | | // 更新 |
| | | updateById(deptVO); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | |
| | | |
| | | String deptIds = ""; |
| | | int count = 0; |
| | | for (String key:deptMap.keySet()){ |
| | | for (String key : deptMap.keySet()) { |
| | | count++; |
| | | deptIds += key; |
| | | if (count<deptMap.size()){ |
| | | deptIds +=","; |
| | | if (count < deptMap.size()) { |
| | | deptIds += ","; |
| | | } |
| | | } |
| | | |
| | |
| | | public Object dataHandleCommunityByPolice() { |
| | | // 查询所有的派出所 |
| | | QueryWrapper<Dept> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).like("dept_name","派出所"); |
| | | wrapper.eq("is_deleted", 0).like("dept_name", "派出所"); |
| | | List<Dept> list = list(wrapper); |
| | | // 遍历 |
| | | for (Dept dept : list) { |
| | | // 通过派出所名称查询对应的警务网格信息 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).eq("pcs_name",dept.getDeptName()); |
| | | List<PoliceAffairsGridEntity> policeAffairsGridEntityList |
| | | = SpringUtil.getBean(IPoliceAffairsGridService.class).list(queryWrapper); |
| | | // 遍历 |
| | | for (PoliceAffairsGridEntity policeAffairsGridEntity : policeAffairsGridEntityList) { |
| | | Dept deptInfo = new Dept(); |
| | | deptInfo.setTenantId("000000"); |
| | | deptInfo.setDeptName(policeAffairsGridEntity.getCommunityName()); |
| | | deptInfo.setFullName(policeAffairsGridEntity.getCommunityName()); |
| | | deptInfo.setDeptCategory(1); |
| | | deptInfo.setDeptNature(1); |
| | | deptInfo.setParentId(dept.getId()); |
| | | deptInfo.setAncestors(dept.getAncestors() + "," + dept.getId()); |
| | | deptInfo.setRegionCode(policeAffairsGridEntity.getJwGridCode()); |
| | | // 保存 |
| | | save(deptInfo); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 查询对应的派出所 |
| | | * |
| | | * @param deptId |
| | | * @return |
| | | */ |