人员所属部门下拉对齐旧项目:主账提供 /departments 短名全量,后台可搜可选。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+35
-2
@@ -22,8 +22,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -147,9 +149,40 @@ public class InquiryStaffRoleController extends JeecgController<InquiryStaffRole
|
||||
}
|
||||
|
||||
/**
|
||||
* 企微部门下拉选项。浏览器禁止直连企微,只打本接口。
|
||||
* 员工「所属部门」下拉(对齐旧项目 admin-rel26)。
|
||||
* <p>
|
||||
* 旧前端:{@code GET /inquiry/staffRole/departments} → {@code string[]},
|
||||
* 再 {@code options: names.map(n => ({label:n,value:n}))},showSearch 可滚动全量。
|
||||
* 本接口同源:企微 {@code department/list} 短名全量;根公司(id=1)不进下拉。
|
||||
* 浏览器禁止直连企微。
|
||||
*/
|
||||
@ApiOperation("企微部门列表")
|
||||
@ApiOperation("员工部门名列表(对齐旧项目 /departments)")
|
||||
@RequiresPermissions("inquiry:staff:list")
|
||||
@GetMapping("/departments")
|
||||
public Result<List<String>> departments() {
|
||||
List<WeComDepartment> all = weComAddressBookClient.listDepartments();
|
||||
List<String> names = new ArrayList<>();
|
||||
LinkedHashSet<String> seen = new LinkedHashSet<>();
|
||||
for (WeComDepartment d : all) {
|
||||
if (d == null || StringUtils.isBlank(d.getName())) {
|
||||
continue;
|
||||
}
|
||||
// 企微根部门(id=1 / parentid=0)是公司全称,员工下拉不展示
|
||||
if (d.getId() == 1 || d.getParentId() <= 0) {
|
||||
continue;
|
||||
}
|
||||
String name = d.getName().trim();
|
||||
if (seen.add(name)) {
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
return Result.OK(names);
|
||||
}
|
||||
|
||||
/**
|
||||
* 企微部门结构列表(含 id/path,供排查)。员工下拉请用 {@link #departments()}。
|
||||
*/
|
||||
@ApiOperation("企微部门结构列表")
|
||||
@RequiresPermissions("inquiry:staff:list")
|
||||
@GetMapping("/wecomDepartments")
|
||||
public Result<List<WeComDepartment>> wecomDepartments() {
|
||||
|
||||
+4
-3
@@ -127,8 +127,9 @@ public class WeComAddressBookClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取企微部门树(扁平列表,带 path 便于下拉展示)。
|
||||
* 拉取企微 {@code department/list} 全量扁平列表(短名 + path)。
|
||||
* <p>
|
||||
* 员工下拉与旧项目同源:整份通讯录,不截层级。顺序保持企微返回序。
|
||||
* 副作用:出站 HTTP;失败抛 IllegalStateException。
|
||||
*/
|
||||
public List<WeComDepartment> listDepartments() {
|
||||
@@ -163,8 +164,8 @@ public class WeComAddressBookClient {
|
||||
String path = buildDepartmentPath(id, byId);
|
||||
result.add(new WeComDepartment(id, name, parentId, path));
|
||||
}
|
||||
// 按路径排序,下拉更易扫
|
||||
result.sort((a, b) -> StringUtils.defaultString(a.getPath()).compareTo(StringUtils.defaultString(b.getPath())));
|
||||
// 保持企微 department/list 原序(LinkedHashMap 插入序 = 接口返回序),
|
||||
// 不要按 path 重排,也不要截层级;员工下拉与旧项目一样用这份全量短名。
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user