作者 yangfu

部门id修改

... ... @@ -8,11 +8,11 @@ import (
)
type Department struct {
Id int `orm:"column(id);auto"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
Id int64 `orm:"column(id);auto"`
CompanyId int64 `orm:"column(company_id)" description:"公司id"`
Name string `orm:"column(name);size(30)" description:"部门名称"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
ParentId int `orm:"column(parent_id)" description:"父级id"`
ParentId int64 `orm:"column(parent_id)" description:"父级id"`
Relation string `orm:"column(relation);size(400)" description:"父子级关系树"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
... ... @@ -37,7 +37,7 @@ func AddDepartment(m *Department) (id int64, err error) {
// GetDepartmentById retrieves Department by Id. Returns error if
// Id doesn't exist
func GetDepartmentById(id int) (v *Department, err error) {
func GetDepartmentById(id int64) (v *Department, err error) {
o := orm.NewOrm()
v = &Department{Id: id}
if err = o.Read(v); err == nil {
... ... @@ -63,7 +63,7 @@ func UpdateDepartmentById(m *Department) (err error) {
// DeleteDepartment deletes Department by Id and returns error if
// the record to be deleted doesn't exist
func DeleteDepartment(id int) (err error) {
func DeleteDepartment(id int64) (err error) {
o := orm.NewOrm()
v := Department{Id: id}
// ascertain id exists in the database
... ...
... ... @@ -125,7 +125,7 @@ type DepartmentStatistics struct {
/*DepartmentStatistic 单部门统计*/
type DepartmentStatisticRequest struct {
DepartmentId int `json:"departmentId"`
DepartmentId int64 `json:"departmentId"`
}
type DepartmentStatisticResponse struct {
DepartmentStatistic DepartmentStatistics `json:"departmentStatistic"`
... ...
... ... @@ -47,7 +47,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, departmentId int, isInclude
lastId = chance.ApproveTime.Unix()
}
if departmentId > 0 {
dIds, _ = GetDepartmentIds(cid, departmentId, isIncludeSubDeps)
dIds, _ = GetDepartmentIds(cid, int64(departmentId), isIncludeSubDeps)
}
log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid))
switch check {
... ...
... ... @@ -103,12 +103,12 @@ func ChanceApprovingStatistic(header *protocol.RequestHeader, departmentIds []in
//获取部门以及子部门编号
//@isIncludeSubDeps 是否包含子部门
func GetDepartmentIds(companyId int64, dId int, isIncludeSubDeps bool) (departmentIds []int, err error) {
func GetDepartmentIds(companyId int64, dId int64, isIncludeSubDeps bool) (departmentIds []int, err error) {
if dId == 0 {
return []int{}, nil
}
if !isIncludeSubDeps {
return []int{dId}, nil
return []int{int(dId)}, nil
}
if d, e := models.GetDepartmentById(dId); e != nil {
log.Error(err)
... ...
... ... @@ -20,7 +20,7 @@ func AchievementPool(header *protocol.RequestHeader, request *protocol.Achieveme
rsp = &protocol.AchievementPoolResponse{}
rsp.List = make([]*protocol.AchievementCommonListItem, 0)
if request.DepartmentId > 0 && request.IncludeSubDepartment {
if d, e := models.GetDepartmentById(request.DepartmentId); e != nil {
if d, e := models.GetDepartmentById(int64(request.DepartmentId)); e != nil {
log.Error(err)
err = e
return
... ...
... ... @@ -1336,13 +1336,13 @@ func resolveActionType(t uint) string {
func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) {
var (
departments *models.Department
lastDepartmentId int
lastDepartmentId int64
)
//if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil {
// log.Error(header.UserId,header.CompanyId,err)
// return
//}
if departments, err = models.GetDepartmentById(int(relatedDeparmentId)); err != nil {
if departments, err = models.GetDepartmentById(relatedDeparmentId); err != nil {
log.Error(relatedDeparmentId, err)
return
}
... ... @@ -1370,7 +1370,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64)
if departments.ParentId != 0 {
//relatedDeparmentId = int64departments.ParentId
lastDepartmentId = departments.ParentId
if departments, err = models.GetDepartmentById(int(departments.ParentId)); err != nil {
if departments, err = models.GetDepartmentById(departments.ParentId); err != nil {
log.Error(departments.ParentId, err)
err = nil
break
... ... @@ -1409,7 +1409,7 @@ func getRoleUsers(header *protocol.RequestHeader, roleId int) (ids []int64, err
}
//递归寻找上一级部门长
func getParentDepartmentors(pid int) (ids []int64) {
func getParentDepartmentors(pid int64) (ids []int64) {
var (
department *models.Department
err error
... ...
... ... @@ -52,7 +52,7 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
//遍历部门
func walkDepartment(to *protocol.Department, dfrom *models.Department) (err error) {
var newD *protocol.Department = &protocol.Department{
DepartmentId: dfrom.Id,
DepartmentId: int(dfrom.Id),
Name: dfrom.Name,
CreateTime: dfrom.CreateAt,
Departments: []*protocol.Department{},
... ... @@ -63,7 +63,7 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro
return
}
}
if to.DepartmentId == dfrom.ParentId {
if to.DepartmentId == int(dfrom.ParentId) {
to.Departments = append(to.Departments, newD)
}
for i := range to.Departments {
... ... @@ -86,7 +86,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
companyDep := departmentsResponse.GetCompanyDepartment()
if companyDep.DepartmentId > 0 {
var companyDepStatistic *protocol.DepartmentStatisticResponse
if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: companyDep.DepartmentId}); err != nil {
if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: int64(companyDep.DepartmentId)}); err != nil {
log.Error(err)
return
}
... ... @@ -155,7 +155,7 @@ func DepartmentStatistic(header *protocol.RequestHeader, request *protocol.Depar
}
departmentStatistic := protocol.DepartmentStatistics{}
departmentStatistic.Dep = protocol.Dep{
Id: deparment.Id,
Id: int(deparment.Id),
Name: deparment.Name,
}
if dIds, err = agg.GetDepartmentIds(header.CompanyId, request.DepartmentId, false); err != nil {
... ... @@ -163,7 +163,7 @@ func DepartmentStatistic(header *protocol.RequestHeader, request *protocol.Depar
return
}
departmentStatistic.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds)
departmentStatistic.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, request.DepartmentId, false, 0, 0, nil)
departmentStatistic.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, int(request.DepartmentId), false, 0, 0, nil)
departmentStatistic.ACTotal = departmentStatistic.AchievementTotal + departmentStatistic.ChanceApprovedTotal
departmentStatistic.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, dIds)
rsp.DepartmentStatistic = departmentStatistic
... ...
... ... @@ -245,12 +245,12 @@ func GetRankSortItems(header *protocol.RequestHeader, request *protocol.GetRankS
return
}
if len(sortItems) > 0 {
rsp.RankSortItems = sortItems
}
if len(sortItems) > 4 {
rsp.RankSortItems = sortItems[0:4]
return
}
rsp.RankSortItems = sortItems
}
return
}
... ...