PHP to Java Code Conversion: Finding Leaders in a Hierarchy
<p>public void getLeaderInfoNew(boolean isFid, ArrayList<Object> fidWhere) {
this.param.put("is_show_all", this.param.getOrDefault("is_show_all", false));
this.param.put("sub_level", this.param.getOrDefault("sub_level", true));
this.param.put("leader_level", this.param.getOrDefault("leader_level", 1));
// this.param['sub_level'] = $this->param['sub_level'] && !$this->param['is_show_all'];
HashMap<String, Object> params = this.param;
Object apply_deptbasedoc_id = this.param.getOrDefault("apply_deptbasedoc_id", null); // 发起人的主部门 用来判断分管领导审单的
ArrayList<HashMap<String, Object>> charge_dept = new ChargeDept().where("charge_dept_id", apply_deptbasedoc_id).cache("charge_dept_id" + apply_deptbasedoc_id, 60).select().toArray();
HashMap<String, Object> charge_dept_arr = new HashMap<>();
for (HashMap<String, Object> dept : charge_dept) {
charge_dept_arr.put(dept.get("deptbasedoc_id"), dept.get("base_user_id"));
}
boolean error = false;
if (!isFid) {
Object baseUserId = this.param.get("psndoc_id");
if (baseUserId == null || baseUserId.equals("")) {
return this.error("人员信息不能为空");
}
if ((this.param.get("shop_code") == null || this.param.get("shop_code").equals("")) && (this.param.get("company_code") == null || this.param.get("company_code").equals(""))) {
return this.error("店铺号不能为空");
}
this.param.put("shop_code", this.param.getOrDefault("shop_code", this.param.get("company_code")));
HashMap<String, Object> where = new HashMap<>();
if (this.param.get("deptbasedoc_id") != null && !this.param.get("deptbasedoc_id").equals("")) {
Object mainDept = this.param.get("deptbasedoc_id");
} else {
Object mainDept = new DeptPsnInfo().where("base_user_id", baseUserId).value("deptbasedoc_id");
// $where[] = ['<strong>TABLE</strong>.id','=',$mainDept];
}
Object shop_code = new DeptBaseDoc().where("id", mainDept).value("shop_code");
this.param.put("shop_code", shop_code);
ArrayList<HashMap<String, Object>> all = new DeptBaseDoc().field("id,fid,deptcode,deptname,deptlevel").where("shop_code", this.param.get("shop_code")).select();
ArrayList<HashMap<String, Object>> parent = all.parent(mainDept).toArray();
ArrayList<String> dept_ids = new ArrayList<>();
for (HashMap<String, Object> p : parent) {
dept_ids.add(p.get("id"));
}
ArrayList<HashMap<String, Object>> leader_all = new DeptPsn().alias("a").leftJoin("bd_deptbasedoc b", "b.id=a.deptbasedoc_id").whereIn("a.deptbasedoc_id", dept_ids).field("a.leader_psndoc_id,a.leader_psndoc_id_2,a.deptbasedoc_id,b.deptname,b.deptcode,b.deptlevel,b.fid").select().toArray();
ArrayList<HashMap<String, Object>> depts = new ChargeDept().whereIn("deptbasedoc_id", dept_ids).select().toArray();
HashMap<String, ArrayList<Object>> depts_arr = new HashMap<>();
if (depts.size() > 0) {
for (HashMap<String, Object> dept : depts) {
if (!depts_arr.containsKey(dept.get("deptbasedoc_id"))) {
depts_arr.put(dept.get("deptbasedoc_id"), new ArrayList<>());
}
depts_arr.get(dept.get("deptbasedoc_id")).add(dept.get("charge_dept_id"));
}
}
if (leader_all.size() > 0) {
for (int i = 0; i < leader_all.size(); i++) {
HashMap<String, Object> o = leader_all.get(i);
if (depts_arr.containsKey(o.get("deptbasedoc_id"))) {
o.put("leader_psndoc_id_2", null);
}
if (charge_dept_arr.containsKey(o.get("deptbasedoc_id"))) {
o.put("leader_psndoc_id_2", charge_dept_arr.get(o.get("deptbasedoc_id")));
}
if (o.get("leader_psndoc_id") == null && o.get("leader_psndoc_id_2") != null && !o.get("leader_psndoc_id_2").equals("")) {
leader_all.get(i).put("leader_psndoc_id", o.get("leader_psndoc_id_2"));
leader_all.get(i).put("leader_psndoc_id_2", "");
}
}
ArrayList<Object> base_user_ids = new ArrayList<>();
for (HashMap<String, Object> item : leader_all) {
base_user_ids.add(item.get("leader_psndoc_id"));
}
if (this.param.get("sub_level")) {
ArrayList<Object> base_user_ids2 = new ArrayList<>();
for (HashMap<String, Object> item : leader_all) {
base_user_ids2.add(item.get("leader_psndoc_id_2"));
}
base_user_ids.addAll(base_user_ids2);
}
ArrayList<HashMap<String, Object>> users = new DeptPsnInfo().whereIn("base_user_id", base_user_ids).field("emp_name as userName", "user_code as userCode", "base_user_id as userId", "base_user_id as baseUserId").select().toArray();
HashMap<String, HashMap<String, Object>> user_arrs = new HashMap<>();
for (HashMap<String, Object> user : users) {
user_arrs.put(user.get("baseUserId"), user);
}
leader_all = this.get_my_sort(leader_all, "deptlevel", 99999, 1);
for (HashMap<String, Object> item : leader_all) {
item.put("is_sub", false);
}
int iii = 1;
for (int i = 0; i < leader_all.size(); i++) {
HashMap<String, Object> item = leader_all.get(i);
if (this.param.get("sub_level")) {
HashMap<String, Object> newItem = item;
if ((item.get("leader_psndoc_id_2") != null && !mainDept.equals(item.get("deptbasedoc_id"))) || (item.get("leader_psndoc_id_2") != null && mainDept.equals(item.get("deptbasedoc_id")) && !item.get("leader_psndoc_id").equals(baseUserId))) {
newItem.put("is_sub", true);
newItem.put("leader_psndoc_id", item.get("leader_psndoc_id_2"));
leader_all.add(i + iii, newItem);
iii++;
}
}
}
for (int i = 0; i < leader_all.size(); i++) {
HashMap<String, Object> item = leader_all.get(i);
if (item.get("leader_psndoc_id") == null || !user_arrs.containsKey(item.get("leader_psndoc_id"))) {
leader_all.remove(i);
} else {
leader_all.get(i).put("leader_info", user_arrs.get(item.get("leader_psndoc_id")));
if (this.param.get("team_leader_level") != null && Integer.parseInt(item.get("deptlevel").toString()) > Integer.parseInt(this.param.get("team_leader_level").toString())) {
leader_all.remove(i);
} else {
if (mainDept.equals(item.get("deptbasedoc_id"))) {
if (item.get("deptlevel").equals(1) && !item.get("leader_psndoc_id").equals(item.get("leader_psndoc_id_2")) && item.get("leader_psndoc_id").equals(baseUserId)) {
leader_all.get(i).put("deptlevel", 0);
leader_all.get(i).put("leader_info", new HashMap<String, Object>() {{
put("userName", "暂无直属主管,自动通过");
put("userCode", "");
}});
} else {
if (item.get("leader_psndoc_id").equals(baseUserId)) {
leader_all.remove(i);
}
}
}
}
}
if (params.get("no_up_find_leader") != null && params.get("no_up_find_leader").equals(1)) {
if (this.param.get("team_leader_level") != null) {
i</p>
原文地址: https://www.cveoy.top/t/topic/pdkw 著作权归作者所有。请勿转载和采集!