|
@@ -6,14 +6,8 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.txz.operating.core.AbstractService;
|
|
import com.txz.operating.core.AbstractService;
|
|
import com.txz.operating.core.ServiceException;
|
|
import com.txz.operating.core.ServiceException;
|
|
import com.txz.operating.dao.DivisionsMapper;
|
|
import com.txz.operating.dao.DivisionsMapper;
|
|
-import com.txz.operating.model.Districts;
|
|
|
|
-import com.txz.operating.model.Divisions;
|
|
|
|
-import com.txz.operating.model.Unions;
|
|
|
|
-import com.txz.operating.model.Upazilas;
|
|
|
|
-import com.txz.operating.service.DistrictsService;
|
|
|
|
-import com.txz.operating.service.DivisionsService;
|
|
|
|
-import com.txz.operating.service.UnionsService;
|
|
|
|
-import com.txz.operating.service.UpazilasService;
|
|
|
|
|
|
+import com.txz.operating.model.*;
|
|
|
|
+import com.txz.operating.service.*;
|
|
import com.txz.operating.web.vo.AreaTreeVo;
|
|
import com.txz.operating.web.vo.AreaTreeVo;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -42,86 +36,119 @@ public class DivisionsServiceImpl extends AbstractService<Divisions> implements
|
|
@Resource
|
|
@Resource
|
|
private UnionsService unionsService;
|
|
private UnionsService unionsService;
|
|
|
|
|
|
- @Override
|
|
|
|
- public List<AreaTreeVo> treeList(String name, Integer pid) {
|
|
|
|
- List<Divisions> allTree = findAll();
|
|
|
|
- if (CollectionUtils.isEmpty(allTree)) {
|
|
|
|
- return Collections.emptyList();
|
|
|
|
- }
|
|
|
|
- // 获取所有树
|
|
|
|
- List<AreaTreeVo> treeVoList = allTree.stream()
|
|
|
|
- .map(divisions -> {
|
|
|
|
- AreaTreeVo vo = new AreaTreeVo();
|
|
|
|
- BeanUtil.copyProperties(divisions, vo);
|
|
|
|
- vo.setLevel(1);
|
|
|
|
- vo.setPid(null);
|
|
|
|
- return vo;
|
|
|
|
- })
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
|
|
- // 如果传入了code,则只返回该code下的树形结构,否则返回所有顶级节点的树形结构
|
|
|
|
- if (StringUtils.isNotBlank(name)) {
|
|
|
|
- // 查找指定code的节点
|
|
|
|
- AreaTreeVo root = treeVoList.stream()
|
|
|
|
- .filter(vo -> name.equals(vo.getName()))
|
|
|
|
- .findFirst()
|
|
|
|
- .orElse(null);
|
|
|
|
- if (root == null) {
|
|
|
|
- Districts districts = districtsService.findBy("name", name);
|
|
|
|
- if (districts != null && districts.getDivisionId().equals(pid)) {
|
|
|
|
- root = new AreaTreeVo();
|
|
|
|
- BeanUtil.copyProperties(districts, root);
|
|
|
|
- root.setPid(districts.getDivisionId());
|
|
|
|
- root.setLevel(2);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (root == null) {
|
|
|
|
- Condition upazilasCondition = new Condition(Upazilas.class);
|
|
|
|
- Example.Criteria upazilasCriteria = upazilasCondition.createCriteria();
|
|
|
|
- upazilasCriteria.andEqualTo("districtId", pid);
|
|
|
|
- upazilasCriteria.andEqualTo("name", name);
|
|
|
|
- List<Upazilas> upazilasList = upazilasService.findByCondition(upazilasCondition);
|
|
|
|
- if (upazilasList.size() > 1 && pid == null) {
|
|
|
|
- throw new ServiceException("当前地区有多个,请输入上级");
|
|
|
|
- }
|
|
|
|
- upazilasList = upazilasList.stream()
|
|
|
|
- .filter(unions -> unions.getDistrictId().equals(pid))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- if (upazilasList.size() == 1) {
|
|
|
|
- root = new AreaTreeVo();
|
|
|
|
- BeanUtil.copyProperties(upazilasList.get(0), root);
|
|
|
|
- root.setPid(upazilasList.get(0).getDistrictId());
|
|
|
|
- root.setLevel(3);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (root == null) {
|
|
|
|
- Condition unionsCondition = new Condition(Unions.class);
|
|
|
|
- Example.Criteria unionsCriteria = unionsCondition.createCriteria();
|
|
|
|
- unionsCriteria.andEqualTo("upazillaId", pid);
|
|
|
|
- unionsCriteria.andEqualTo("name", name);
|
|
|
|
- List<Unions> unionsList = unionsService.findByCondition(unionsCondition);
|
|
|
|
- if (unionsList.size() > 1 && pid == null) {
|
|
|
|
- throw new ServiceException("当前地区有多个,请输入上级");
|
|
|
|
- }
|
|
|
|
- unionsList = unionsList.stream()
|
|
|
|
- .filter(unions -> unions.getUpazillaId().equals(pid))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- if (unionsList.size() == 1) {
|
|
|
|
- root = new AreaTreeVo();
|
|
|
|
- BeanUtil.copyProperties(unionsList.get(0), root);
|
|
|
|
- root.setPid(unionsList.get(0).getUpazillaId());
|
|
|
|
- root.setLevel(4);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (root == null) {
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Divisions 省
|
|
|
|
+ * <p>
|
|
|
|
+ * <p>
|
|
|
|
+ * districts 区(二级市)
|
|
|
|
+ * <p>
|
|
|
|
+ * upazilas 副区(三级区)
|
|
|
|
+ * <p>
|
|
|
|
+ * unions 联盟四级街道
|
|
|
|
+ */
|
|
|
|
+ @Resource
|
|
|
|
+ private AddrService addrService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<AreaTreeVo> treeList(Integer pid) {
|
|
|
|
+ Condition c = new Condition(Addr.class);
|
|
|
|
+ c.createCriteria().andEqualTo("pid", pid);
|
|
|
|
+ List<Addr> addrByCondition = addrService.findByCondition(c);
|
|
|
|
+ List<AreaTreeVo> areaTreeVos = new ArrayList<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(addrByCondition)) {
|
|
|
|
+ for (Addr addr : addrByCondition) {
|
|
|
|
+ AreaTreeVo areaTreeVo = new AreaTreeVo();
|
|
|
|
+ areaTreeVo.setId(addr.getId());
|
|
|
|
+ areaTreeVo.setPid(addr.getPid());
|
|
|
|
+ areaTreeVo.setName(addr.getName());
|
|
|
|
+ areaTreeVo.setBnName(addr.getBnName());
|
|
|
|
+ areaTreeVos.add(areaTreeVo);
|
|
}
|
|
}
|
|
- // 递归构建该节点下的所有子树
|
|
|
|
- buildTree(root);
|
|
|
|
- return Collections.singletonList(root);
|
|
|
|
}
|
|
}
|
|
|
|
+ return areaTreeVos;
|
|
|
|
+ }
|
|
|
|
|
|
- // 没有name的时候只返第一级
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public List<AreaTreeVo> treeList(String name, Integer pid) {
|
|
|
|
+// List<Divisions> allTree = findAll();
|
|
|
|
+// if (CollectionUtils.isEmpty(allTree)) {
|
|
|
|
+// return Collections.emptyList();
|
|
|
|
+// }
|
|
|
|
+// // 获取所有树
|
|
|
|
+// List<AreaTreeVo> treeVoList = allTree.stream()
|
|
|
|
+// .map(divisions -> {
|
|
|
|
+// AreaTreeVo vo = new AreaTreeVo();
|
|
|
|
+// BeanUtil.copyProperties(divisions, vo);
|
|
|
|
+// vo.setLevel(1);
|
|
|
|
+// vo.setPid(null);
|
|
|
|
+// return vo;
|
|
|
|
+// })
|
|
|
|
+// .collect(Collectors.toList());
|
|
|
|
+//
|
|
|
|
+// // 如果传入了code,则只返回该code下的树形结构,否则返回所有顶级节点的树形结构
|
|
|
|
+// if (StringUtils.isNotBlank(name)) {
|
|
|
|
+// // 查找指定code的节点
|
|
|
|
+// AreaTreeVo root = treeVoList.stream()
|
|
|
|
+// .filter(vo -> name.equals(vo.getName()))
|
|
|
|
+// .findFirst()
|
|
|
|
+// .orElse(null);
|
|
|
|
+// if (root == null) {
|
|
|
|
+// Districts districts = districtsService.findBy("name", name);
|
|
|
|
+// if (districts != null && districts.getDivisionId().equals(pid)) {
|
|
|
|
+// root = new AreaTreeVo();
|
|
|
|
+// BeanUtil.copyProperties(districts, root);
|
|
|
|
+// root.setPid(districts.getDivisionId());
|
|
|
|
+// root.setLevel(2);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (root == null) {
|
|
|
|
+// Condition upazilasCondition = new Condition(Upazilas.class);
|
|
|
|
+// Example.Criteria upazilasCriteria = upazilasCondition.createCriteria();
|
|
|
|
+// upazilasCriteria.andEqualTo("districtId", pid);
|
|
|
|
+// upazilasCriteria.andEqualTo("name", name);
|
|
|
|
+// List<Upazilas> upazilasList = upazilasService.findByCondition(upazilasCondition);
|
|
|
|
+// if (upazilasList.size() > 1 && pid == null) {
|
|
|
|
+// throw new ServiceException("当前地区有多个,请输入上级");
|
|
|
|
+// }
|
|
|
|
+// upazilasList = upazilasList.stream()
|
|
|
|
+// .filter(unions -> unions.getDistrictId().equals(pid))
|
|
|
|
+// .collect(Collectors.toList());
|
|
|
|
+// if (upazilasList.size() == 1) {
|
|
|
|
+// root = new AreaTreeVo();
|
|
|
|
+// BeanUtil.copyProperties(upazilasList.get(0), root);
|
|
|
|
+// root.setPid(upazilasList.get(0).getDistrictId());
|
|
|
|
+// root.setLevel(3);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (root == null) {
|
|
|
|
+// Condition unionsCondition = new Condition(Unions.class);
|
|
|
|
+// Example.Criteria unionsCriteria = unionsCondition.createCriteria();
|
|
|
|
+// unionsCriteria.andEqualTo("upazillaId", pid);
|
|
|
|
+// unionsCriteria.andEqualTo("name", name);
|
|
|
|
+// List<Unions> unionsList = unionsService.findByCondition(unionsCondition);
|
|
|
|
+// if (unionsList.size() > 1 && pid == null) {
|
|
|
|
+// throw new ServiceException("当前地区有多个,请输入上级");
|
|
|
|
+// }
|
|
|
|
+// unionsList = unionsList.stream()
|
|
|
|
+// .filter(unions -> unions.getUpazillaId().equals(pid))
|
|
|
|
+// .collect(Collectors.toList());
|
|
|
|
+// if (unionsList.size() == 1) {
|
|
|
|
+// root = new AreaTreeVo();
|
|
|
|
+// BeanUtil.copyProperties(unionsList.get(0), root);
|
|
|
|
+// root.setPid(unionsList.get(0).getUpazillaId());
|
|
|
|
+// root.setLevel(4);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (root == null) {
|
|
|
|
+// return Collections.emptyList();
|
|
|
|
+// }
|
|
|
|
+// // 递归构建该节点下的所有子树
|
|
|
|
+// buildTree(root);
|
|
|
|
+// return Collections.singletonList(root);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ // 没有name的时候只返第一级
|
|
// else {
|
|
// else {
|
|
// // 为每个顶级节点递归构建子树
|
|
// // 为每个顶级节点递归构建子树
|
|
// for (AreaTreeVo root : treeVoList) {
|
|
// for (AreaTreeVo root : treeVoList) {
|
|
@@ -129,8 +156,8 @@ public class DivisionsServiceImpl extends AbstractService<Divisions> implements
|
|
// }
|
|
// }
|
|
// return treeVoList;
|
|
// return treeVoList;
|
|
// }
|
|
// }
|
|
- return treeVoList;
|
|
|
|
- }
|
|
|
|
|
|
+ // return treeVoList;
|
|
|
|
+//}
|
|
|
|
|
|
private void buildTree(AreaTreeVo parent) {
|
|
private void buildTree(AreaTreeVo parent) {
|
|
List<AreaTreeVo> children = new ArrayList<>();
|
|
List<AreaTreeVo> children = new ArrayList<>();
|