6 changed files with 145 additions and 3 deletions
@ -0,0 +1,77 @@ |
|||
package com.zdxt.app.task; |
|||
|
|||
import cn.hutool.core.map.MapUtil; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.zdxt.auth.common.utils.StringUtils; |
|||
import com.zdxt.auth.dto.UserBean; |
|||
import com.zdxt.auth.feign.UserApi; |
|||
import com.zdxt.auth.project.system.dept.service.IDeptService; |
|||
import com.zdxt.auth.project.system.dict.service.IDictDataService; |
|||
import com.zdxt.auth.project.system.user.service.IUserService; |
|||
import com.zdxt.domain.auth.Dept; |
|||
import com.zdxt.domain.auth.DictData; |
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpPost; |
|||
import org.apache.http.entity.StringEntity; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClientBuilder; |
|||
import org.apache.http.util.EntityUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.IOException; |
|||
import java.nio.charset.StandardCharsets; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Paths; |
|||
import java.security.MessageDigest; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
|
|||
/** |
|||
* @Author: kylin |
|||
* @Date: 2024/5/9 2:58 下午 |
|||
* @Version: 1.0 |
|||
* @Desc: TODO |
|||
*/ |
|||
@Component("UpdateDeptTask") |
|||
public class UpdateDeptTask { |
|||
@Autowired private IDeptService deptService; |
|||
|
|||
private static final Logger log = LoggerFactory.getLogger(UpdateDeptTask.class); |
|||
|
|||
|
|||
public void run(){ |
|||
this.updateAncestors(); |
|||
} |
|||
|
|||
public void updateAncestors() { |
|||
// 先查出所有部门的id,parentId 信息
|
|||
List<Dept> deptList = deptService.selectDeptAll(); |
|||
for (Dept dept : deptList) { |
|||
List<String> ancs = new ArrayList<>(); |
|||
ancs = convertAncestors(dept, deptList, ancs); |
|||
ancs.add("0"); |
|||
Collections.reverse(ancs); |
|||
String anc = String.join(",", ancs); |
|||
dept.setAncestors(anc); |
|||
deptService.updateAncestorsById(dept); |
|||
log.info("{} -> {}", dept.getDeptId(), anc); |
|||
} |
|||
} |
|||
|
|||
private List<String> convertAncestors(Dept dept, List<Dept> deptList, List<String> ancs) { |
|||
for (Dept tmp : deptList) { |
|||
if (dept.getParentId().equals(tmp.getDeptId()) && !dept.getDeptId().equals(tmp.getDeptId())) { |
|||
ancs.add(tmp.getDeptId()); |
|||
return convertAncestors(tmp, deptList, ancs); |
|||
} |
|||
} |
|||
return ancs; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue