|
@@ -3,7 +3,9 @@ package com.boman.system.service.impl;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
+import com.boman.system.mapper.SyncMapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -18,6 +20,8 @@ import com.boman.system.mapper.SysDeptMapper;
|
|
|
import com.boman.system.mapper.SysRoleMapper;
|
|
|
import com.boman.system.service.ISysDeptService;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
/**
|
|
|
* 部门管理 服务实现
|
|
|
*
|
|
@@ -350,7 +354,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
*/
|
|
|
@Override
|
|
|
public List<SysDept> listChildrenDepts(Long deptId) {
|
|
|
- List<SysDept> allDepts = selectDeptList(new SysDept());
|
|
|
+ List<SysDept> allDepts = selectDepts(new SysDept());
|
|
|
SysDept sysDept = ObjectUtils.filterOne(allDepts, dept -> deptId.equals(dept.getId()));
|
|
|
List<SysDept> returnData = Lists.newArrayListWithCapacity(16);
|
|
|
List<SysDept> sysDepts = recursionChildrenDepts(allDepts, sysDept, returnData);
|
|
@@ -373,4 +377,125 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
return returnData;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> syncData() throws Exception {
|
|
|
+ List<JSONObject> datas = new ArrayList<>();
|
|
|
+ try{
|
|
|
+ SysDept sysDept = new SysDept();
|
|
|
+ // 所有层级数据
|
|
|
+ List<TreeSelect> depts = this.getDepts(sysDept);
|
|
|
+ // 乡镇
|
|
|
+ List<TreeSelect> regionDept = this.getRegionDept(depts);
|
|
|
+ Map<String, Long> regionMap = new HashMap<>();
|
|
|
+ for (TreeSelect treeSelect : regionDept) {
|
|
|
+ regionMap.put(treeSelect.getLabel(), treeSelect.getId());
|
|
|
+ }
|
|
|
+ // 村
|
|
|
+ Map<String, Long> repeatVillageMap = new HashMap<>();
|
|
|
+ List<TreeSelect> villegeDept = this.getVillegeDept(depts, repeatVillageMap);
|
|
|
+ Map<String, Long> villegeMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ for (TreeSelect treeSelect : villegeDept) {
|
|
|
+ String deptName = treeSelect.getLabel();
|
|
|
+ Long deptId = treeSelect.getId();
|
|
|
+ if(villegeMap.containsKey(deptName)) {
|
|
|
+ System.out.println(deptName);
|
|
|
+ }
|
|
|
+ villegeMap.put(deptName, deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<JSONObject> vaccInfos = this.getVaccInfo();
|
|
|
+ for (JSONObject vanninfo : vaccInfos) {
|
|
|
+ String idCard = vanninfo.getString("zjhm");
|
|
|
+ String dz = vanninfo.getString("hjdxz");
|
|
|
+ JSONObject update = new JSONObject();
|
|
|
+ update.put("id_card", idCard);
|
|
|
+ // 先判断村数据是否存在,如果村存在,则直接获取村的id,反之获取乡镇id
|
|
|
+ Long deptId = this.getVillegeDeptId(dz, villegeMap, repeatVillageMap);
|
|
|
+ if(deptId == null) {
|
|
|
+ deptId = this.getRegionDeptId(dz, regionMap);
|
|
|
+ }
|
|
|
+ update.put("dept_id", deptId);
|
|
|
+ System.out.println(update.toJSONString());
|
|
|
+ datas.add(update);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SyncMapper syncMapper;
|
|
|
+
|
|
|
+ private List<JSONObject> getVaccInfo() {
|
|
|
+ String sql = "select * from hj_hj";
|
|
|
+ List<JSONObject> objs = syncMapper.selectBySql(sql);
|
|
|
+ return objs;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TreeSelect> getDepts(SysDept dept) {
|
|
|
+ return buildDeptTreeSelect(this.selectDepts(dept));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TreeSelect> getRegionDept(List<TreeSelect> depts) {
|
|
|
+ return depts.get(0).getChildren();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TreeSelect> getVillegeDept(List<TreeSelect> depts, Map<String, Long> repeatVillageMap) {
|
|
|
+ List<TreeSelect> villegs = new ArrayList<>();
|
|
|
+ List<TreeSelect> regions = depts.get(0).getChildren();
|
|
|
+ for (TreeSelect region : regions) {
|
|
|
+ if(region.getLabel().equals("王河镇") || region.getLabel().equals("五庙乡")
|
|
|
+ || region.getLabel().equals("黄铺镇") || region.getLabel().equals("水吼镇") ) {
|
|
|
+ List<TreeSelect> vills = region.getChildren();
|
|
|
+ for (TreeSelect vill : vills) {
|
|
|
+ if(vill.getLabel().equals("和平村") || vill.getLabel().equals("红光村")) {
|
|
|
+ repeatVillageMap.put(region.getLabel() + vill.getLabel(), vill.getId());
|
|
|
+ }else{
|
|
|
+ villegs.add(vill);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ villegs.addAll(region.getChildren());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return villegs;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getRegionDeptId(String dz, Map<String, Long> villegeMap) {
|
|
|
+ for (String deptName : villegeMap.keySet()) {
|
|
|
+ if(dz.contains(deptName)) {
|
|
|
+ return villegeMap.get(deptName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getVillegeDeptId(String dz, Map<String, Long> villegeMap, Map<String, Long> repeatVillageMap) {
|
|
|
+ if(dz.contains("和平村") || dz.contains("红光村")) {
|
|
|
+ if(dz.contains("黄铺镇" + "和平村")) {
|
|
|
+ return repeatVillageMap.get("黄铺镇" + "和平村");
|
|
|
+ }else if(dz.contains("水吼镇" + "和平村")){
|
|
|
+ return repeatVillageMap.get("水吼镇" + "和平村");
|
|
|
+ }else if(dz.contains("王河镇" + "红光村")) {
|
|
|
+ return repeatVillageMap.get("王河镇" + "红光村");
|
|
|
+ }else if(dz.contains("五庙乡" + "红光村")){
|
|
|
+ return repeatVillageMap.get("五庙乡" + "红光村");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ for (String deptName : villegeMap.keySet()) {
|
|
|
+ if(dz.contains(deptName)) {
|
|
|
+ return villegeMap.get(deptName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
}
|