优化backend端相关功能
This commit is contained in:
@@ -29,24 +29,22 @@ func (c *BackendOrganizationController) organizationDTOList(tid uint64, rows []m
|
||||
|
||||
nameByID := c.orgNameMap(tid)
|
||||
leaderNames := c.employeeNameMap(tid)
|
||||
counts := c.employeeCountByDepartment(tid)
|
||||
|
||||
for _, row := range rows {
|
||||
list = append(list, c.assembleOrganizationDTO(row, nameByID, leaderNames, counts))
|
||||
list = append(list, c.assembleOrganizationDTO(row, nameByID, leaderNames))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (c *BackendOrganizationController) organizationDTO(tid uint64, row models.BackendOrganization) organizationDTO {
|
||||
return c.assembleOrganizationDTO(row,
|
||||
c.orgNameMap(tid), c.employeeNameMap(tid), c.employeeCountByDepartment(tid))
|
||||
c.orgNameMap(tid), c.employeeNameMap(tid))
|
||||
}
|
||||
|
||||
func (c *BackendOrganizationController) assembleOrganizationDTO(
|
||||
row models.BackendOrganization,
|
||||
nameByID map[uint64]string,
|
||||
leaderNames map[uint64]string,
|
||||
counts map[string]int64,
|
||||
) organizationDTO {
|
||||
leaderID := uint64(0)
|
||||
if row.LeaderID != nil {
|
||||
@@ -67,7 +65,6 @@ func (c *BackendOrganizationController) assembleOrganizationDTO(
|
||||
Sort: row.Sort,
|
||||
Status: row.Status,
|
||||
Remark: derefString(row.Remark),
|
||||
EmployeeCount: counts[strconv.FormatUint(row.ID, 10)],
|
||||
CreateTime: formatDateTime(&row.CreateTime),
|
||||
UpdateTime: formatDateTime(&row.UpdateTime),
|
||||
}
|
||||
@@ -179,23 +176,6 @@ func (c *BackendOrganizationController) employeeNameMap(tid uint64) map[uint64]s
|
||||
return result
|
||||
}
|
||||
|
||||
// employeeCountByDepartment 统计各部门(department 存的是组织ID字符串)的员工数。
|
||||
func (c *BackendOrganizationController) employeeCountByDepartment(tid uint64) map[string]int64 {
|
||||
result := map[string]int64{}
|
||||
var rows []models.BackendEmployee
|
||||
if _, err := c.employeeQuery(tid).All(&rows, "Department"); err != nil {
|
||||
return result
|
||||
}
|
||||
for _, row := range rows {
|
||||
key := strings.TrimSpace(derefString(row.Department))
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
result[key]++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *BackendOrganizationController) orgExists(tid, id uint64) bool {
|
||||
if id == 0 {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user