PHP to Java Code Conversion: Retrieving Leader Information
<p>public void getLeaderInfoNew(boolean isFid, Map<String, Object> fidWhere) {
this.param.put("is_show_all", this.param.get("is_show_all") != null ? this.param.get("is_show_all") : false);
this.param.put("sub_level", this.param.get("sub_level") != null ? this.param.get("sub_level") : true);
this.param.put("leader_level", this.param.get("leader_level") != null ? this.param.get("leader_level") : 1);
Map<String, Object> params = this.param;
Object apply_deptbasedoc_id = this.param.get("apply_deptbasedoc_id") != null ? this.param.get("apply_deptbasedoc_id") : null;
List<ChargeDept> charge_dept = new ChargeDept().where("charge_dept_id", apply_deptbasedoc_id).cache("charge_dept_id" + apply_deptbasedoc_id, 60).select().toArray();
Map<String, Object> charge_dept_arr = array_column(charge_dept, "base_user_id", "deptbasedoc_id");
boolean error = false;
if (!isFid) {
Object baseUserId = this.param.get("psndoc_id");
if (baseUserId == null || baseUserId.toString().isEmpty()) {
return this.error("人员信息不能为空");
}
if ((this.param.get("shop_code") == null || this.param.get("shop_code").toString().isEmpty()) && (this.param.get("company_code") == null || this.param.get("company_code").toString().isEmpty())) {
return this.error("店铺号不能为空");
}
this.param.put("shop_code", this.param.get("shop_code") != null ? this.param.get("shop_code") : this.param.get("company_code"));
Map<String, Object> where = new HashMap<>();
if (this.param.get("deptbasedoc_id") != null && !this.param.get("deptbasedoc_id").toString().isEmpty()) {
Object mainDept = this.param.get("deptbasedoc_id");
} else {
Object mainDept = new DeptPsnInfo().where("base_user_id", baseUserId).value("deptbasedoc_id");
}
Object shop_code = new DeptBaseDoc().where("id", mainDept).value("shop_code");
this.param.put("shop_code", shop_code);
List<Map<String, Object>> all = new DeptBaseDoc().field("id, fid, deptcode, deptname, deptlevel").where("shop_code", this.param.get("shop_code")).select();
List<Map<String, Object>> parent = all.parent(mainDept).toArray();
List<Object> dept_ids = array_column(parent, "id");
List<Map<String, Object>> leader_all = new DeptPsn().alias("a").leftJoin("bd_deptbasedoc b", "b.id=a.deptbasedoc_id").whereIn("a.deptbasedoc_id", dept_ids).field(Arrays.asList("a.leader_psndoc_id", "a.leader_psndoc_id_2", "a.deptbasedoc_id", "b.deptname", "b.deptcode", "b.deptlevel", "b.fid")).select().toArray();
List<Map<String, Object>> depts = new ChargeDept().whereIn("deptbasedoc_id", dept_ids).select().toArray();
Map<String, List<Object>> depts_arr = new HashMap<>();
if (depts != null) {
for (Map<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 != null) {
for (Map<String, Object> o : leader_all) {
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) {
leader_all.get(ko).put("leader_psndoc_id", o.get("leader_psndoc_id_2"));
leader_all.get(ko).put("leader_psndoc_id_2", "");
}
}
List<Object> base_user_ids = array_column(leader_all, "leader_psndoc_id");
if (this.param.get("sub_level")) {
List<Object> base_user_ids2 = array_column(leader_all, "leader_psndoc_id_2");
base_user_ids.addAll(base_user_ids2);
}
List<Map<String, Object>> users = new DeptPsnInfo().whereIn("base_user_id", base_user_ids).field(Arrays.asList("emp_name as userName", "user_code as userCode", "base_user_id as userId", "base_user_id as baseUserId")).select().toArray();
Map<Object, Map<String, Object>> user_arrs = array_column(users, null, "baseUserId");
leader_all = get_my_sort(leader_all, "deptlevel", 99999, 1);
for (Map<String, Object> item : leader_all) {
item.put("is_sub", false);
}
int iii = 1;
for (int index = 0; index < leader_all.size(); index++) {
Map<String, Object> item = leader_all.get(index);
if (this.param.get("sub_level")) {
Map<String, Object> newItem = item;
if ((item.get("leader_psndoc_id_2") != null && mainDept != item.get("deptbasedoc_id")) || (item.get("leader_psndoc_id_2") != null && mainDept == item.get("deptbasedoc_id") && item.get("leader_psndoc_id") != baseUserId)) {
newItem.put("is_sub", true);
newItem.put("leader_psndoc_id", item.get("leader_psndoc_id_2"));
leader_all.add(index + iii, newItem);
iii++;
}
}
}
for (int index = 0; index < leader_all.size(); index++) {
Map<String, Object> item = leader_all.get(index);
if (item.get("leader_psndoc_id") == null || !user_arrs.containsKey(item.get("leader_psndoc_id"))) {
leader_all.remove(index);
} else {
item.put("leader_info", user_arrs.get(item.get("leader_psndoc_id")));
if (this.param.get("team_leader_level") != null && item.get("deptlevel") > this.param.get("team_leader_level")) {
leader_all.remove(index);
} else {
if (mainDept == item.get("deptbasedoc_id")) {
if (item.get("deptlevel") == 1 && item.get("leader_psndoc_id") != item.get("leader_psndoc_id_2") && item.get("leader_psndoc_id") == baseUserId) {
item.put("deptlevel", 0);
item.get("leader_info").put("userName", "暂无直属主管,自动通过");
item.get("leader_info").put("userCode", "");
} else {
if (item.get("leader_psndoc_id") == baseUserId) {
leader_all.remove(index);
}
}
}
}
}
if (this.param.get("no_up_find_leader") != null && this.param.get("no_up_find_leader") == 1) {
if (this.param.get("team_leader_level") != null) {
if (item.get("deptlevel") != this.param.get("team_leader_level")) {
leader_all.remove(index);
}
} else {
if (mainDept != item.get("deptbasedoc_id")) {
leader_all.remove(index);
}
}
}
}
if (leader_all != null && !leader_all.isEmpty()) {
Collections.reverse(leader_all);
if (this.param.get("is_show_all")) {
return this.success(leader_all);
}
return this.success(Arrays.asList(leader_all.get(0)));
}
error = true;
} else {
error = true;
}
if (error) {
Object mainDept = new DeptPsnInfo().field(Arrays.asList("emp_name", "base_user_id", "user_code")).where("base_user_id", this.param.get("psndoc_id")).find();
if (mainDept == null) {
return this.error("用户信息错误" + json_encode(params, JSON_UNESCAPED_UNICODE));
}
List<Map<String, Object>> dat = new ArrayList<>();
Map<String, Object> leader = new HashMap<>();
leader.put("leader_psndoc_id", mainDept.get("base_user_id"));
leader.put("deptbasedoc_id", params.get("deptbasedoc_id") != null ? params.get("deptbasedoc_id") : "");
leader.put("deptname", "");
leader.put("deptcode", "");
leader.put("deptlevel", 0);
leader.put("fid", null);
Map<String, Object> leader_info = new HashMap<>();
leader_info.put("userName", "暂无直属主管,自动通过");
leader_info.put("userCode", "");
leader_info.put("userId", mainDept.get("base_user_id"));
leader_info.put("baseUserId", mainDept.get("base_user_id"));
leader.put("leader_info", leader_info);
dat.add(leader);
if (this.param.get("is_show_all")) {
return this.success(dat);
}
return this.success(dat.get(0));
}
}
}</p>
原文地址: https://www.cveoy.top/t/topic/pdkx 著作权归作者所有。请勿转载和采集!