department.go 2.5 KB
package protocol

import (
	"time"
)

const (
	DepartmentUser = iota //用户所有部门
	DepartmentAll         //公司所有部门
	DepartmentRoot        //公司一级部门
)

const (
	StatisticApproved  = 1 //统计已审核
	StatisticApproving = 2 //统计审核中
)

/*Departments */
type DepartmentsRequest struct {
	//Type int `json:"type" valid:"Required"` //1:公司所有部门  2:用户所在部门
	Type int `json:"type"` //0:用户所在部门 1:公司所有部门
}
type DepartmentsResponse struct {
	Departments []*Department `json:"departments,omitempty"`
}

//获取一级部门列表
func (this DepartmentsResponse) GetRootDepartment() []*Department {
	if len(this.Departments) == 0 {
		return []*Department{}
	}
	return this.Departments[0].Departments
}

//获得部门底下子部门的编号列表(包含本身)
func (this DepartmentsResponse) GetChildDepartmentIds(d *Department, isContainSelf bool) []int {
	idList := make([]int, 0)
	if isContainSelf {
		idList = append(idList, d.DepartmentId)
	}
	idList = append(idList, walkDeparment(d)...)
	return idList
}

//遍历部门
func walkDeparment(d *Department) []int {
	idList := make([]int, 0)
	for i := range d.Departments {
		d := d.Departments[i]
		idList = append(idList, d.DepartmentId)
		if len(d.Departments) > 0 {
			idList = append(idList, walkDeparment(d)...)
		}
	}
	return idList
}

type Department struct {
	DepartmentId  int           `orm:"column(department_id)" json:"id"`
	Name          string        `orm:"column(name)" json:"name"`
	PId           int           `orm:"column(parent_id)" json:"-"`
	ManagerString string        `orm:"column(managers)" json:"-"`
	Relation      string        `orm:"column(relation)" json:"-"`
	CreateTime    time.Time     `orm:"column(create_time)" json:"-"`
	Managers      []int         `json:"-"`
	Departments   []*Department `json:"departments,omitempty"`
}

/*DepartmentStatistics 部门统计*/
type DepartmentStatisticsRequest struct {
	//DId int `json:"did"`//部门编号 //查询所有部门 查询特定部门
	Type int `json:"type"` //1:已审核 2:待审核
}
type DepartmentStatisticsResponse struct {
	List []*DepartmentStatistics `json:"departmentStatistics"`
}

//部门统计项
type DepartmentStatistics struct {
	Dep                  Dep `json:"dep"`                  //部门
	ChanceApprovedTotal  int `json:"chanceApprovedTotal"`  //已审核的机会
	ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会
	AchievementTotal     int `json:"achievementTotal"`     //已创建的成果 (显示)
}