作者 yangfu

1.增加部门统计

2.修改用户统计
... ... @@ -33,3 +33,24 @@ func (this *DepartmentController) Departments() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(department.Departments(header, request))
}
//DepartmentStatistics 部门统计
//@router /statistics [post]
func (this *DepartmentController) DepartmentStatistics() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.DepartmentStatisticsRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(department.DepartmentStatistics(header, request))
}
... ...
package v1
import (
"encoding/json"
"opp/controllers"
"opp/protocol"
"opp/services/rank"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)
type RankController struct {
controllers.BaseController
}
//GetRankList 排行榜
// @router /getRankList [post]
func (this *RankController) GetRankList() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.GetRankListRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(rank.GetRankList(header, request))
}
//GetRankType 获取榜单类型列表 (年榜/赛季榜)
// @router /getRankType [post]
func (this *RankController) GetRankType() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.GetRankTypeRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(rank.GetRankType(header, request))
}
//GetRankRange 获取榜单竞争范围列表
//@router /getRankRange [post]
func (this *RankController) GetRankRange() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.GetRankRangeRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(rank.GetRankRange(header, request))
}
//GetRankPeriods 获取排行榜周期列表
//@router /getRankPeriods [post]
func (this *RankController) GetRankPeriods() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.GetRankPeriodsRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(rank.GetRankPeriods(header, request))
}
... ...
package utils
import (
"bytes"
"errors"
"fmt"
"github.com/astaxie/beego/orm"
... ... @@ -183,3 +184,62 @@ func ExecuteSQLWithOrmer(o orm.Ormer, sqlstr string, param ...interface{}) error
log.Debug(fmt.Sprintf("RowsAffected:%d", num))
return nil
}
type SqlExcutor struct {
table string
wherestr []string
orderstr []string
islimit bool
offset int
pagenum int
}
func NewSqlExutor() *SqlExcutor {
return &SqlExcutor{}
}
func (s *SqlExcutor) Table(str string) *SqlExcutor {
s.table = str
return s
}
func (s *SqlExcutor) Where(condition ...string) *SqlExcutor {
if len(condition) <= 0 {
return s
}
s.wherestr = append(s.wherestr, condition...)
return s
}
func (s *SqlExcutor) Order(condition ...string) *SqlExcutor {
if len(condition) <= 0 {
return s
}
s.orderstr = append(s.orderstr, condition...)
return s
}
func (s *SqlExcutor) Limit(page, pagenum int) *SqlExcutor {
offset := 0
if page > 0 {
offset = (page - 1) * pagenum
}
s.islimit = true
s.offset = offset
s.pagenum = pagenum
return s
}
func (s *SqlExcutor) WhereString() string {
sql := bytes.NewBufferString("")
if len(s.wherestr) > 0 {
sql.WriteString(" where ")
for i := range s.wherestr {
if i != 0 {
sql.WriteString(" AND ")
}
sql.WriteString(s.wherestr[i])
}
}
return sql.String()
}
... ...
package models
import (
"bytes"
"fmt"
"opp/internal/utils"
"time"
... ... @@ -66,25 +65,30 @@ func UpdateAchievementById(m *Achievement) (err error) {
//@lastId 最后编号
//@chanceTypeId 机会一级分类编号
//@departmentId 部门编号
func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId int, pageSize int, v interface{}) (total int, err error) {
var whereString bytes.Buffer
if departmentId > 0 {
whereString.WriteString(fmt.Sprintf(` and %v in (select department_id from user_department where user_company_id=achievement.user_company_id and enable_status=1) `, departmentId))
func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId []int, pageSize int, v interface{}) (total int, err error) {
var filter = utils.NewSqlExutor()
filter.Where(fmt.Sprintf("company_id=%v", cid))
filter.Where("status=1")
if lastId > 0 {
filter.Where(fmt.Sprintf("id<%v", lastId))
}
if uid > 0 {
whereString.WriteString(fmt.Sprintf(` and user_company_id=%v `, uid))
if chanceTypeId > 0 {
filter.Where(fmt.Sprintf("chance_type_id =%v", chanceTypeId))
}
if len(departmentId) > 0 {
filter.Where(fmt.Sprintf("department_id in (%v)", utils.JoinInts(departmentId, ",")))
}
sql := fmt.Sprintf(`
select id,user_company_id,create_at,source_content,audit_template_id,chance_type_id,grasp_score,user_grasp_score,comment_total,zan_total,view_total,images from achievement
where company_id=%v and (%v=0 or id<%v) and (%v=0 or chance_type_id =%v) and status=1 %v
select id,user_company_id,create_at,source_content,audit_template_id,chance_type_id,grasp_score,user_grasp_score,comment_total,zan_total,view_total,images from achievement
%v
order by create_at desc
limit %v
`, cid, lastId, lastId, chanceTypeId, chanceTypeId, whereString.String(), pageSize)
limit %v
`, filter.WhereString(), pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from achievement
where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v
`, cid, chanceTypeId, chanceTypeId, whereString.String())
select count(0) from achievement
%v
`, filter.WhereString())
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
... ...
... ... @@ -264,23 +264,23 @@ where user_id =?`
}
//type4 查看所有机会
func GetChancePoolAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
func GetChancePoolAll(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) {
var filterDepartment string = getFilterSqlByDIds(dIds)
sql := fmt.Sprintf(`select a.*,b.images,speechs,videos
from (
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 %v
) a left JOIN chance_data b on a.id =b.chance_id
order by create_at desc
limit ?
`
`, filterDepartment)
//if public==protocol.pu
sqlCount := fmt.Sprintf(`select count(0) from (
select id from chance
where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1
) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)
where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 %v
) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId, filterDepartment)
if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
return
}
... ... @@ -293,8 +293,8 @@ where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and ena
}
//type3 特定部门机会
func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
var filterDepartment string = getFilterSqlByDIds(dIds)
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
... ... @@ -318,11 +318,11 @@ select * from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
) a left JOIN chance_data b on a.id =b.chance_id
order by create_at desc
limit %v
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
... ... @@ -346,8 +346,8 @@ select count(0) from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
... ... @@ -360,8 +360,8 @@ select count(0) from (
}
//type32 特定部门机会 - 多角色时包含levl2 部门公开
func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) {
func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) {
var filterDepartment string = getFilterSqlByDIds(dIds)
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
... ... @@ -393,11 +393,11 @@ select * from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
) a left JOIN chance_data b on a.id =b.chance_id
order by create_at desc
limit %v
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
... ... @@ -429,8 +429,8 @@ select count(0) from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
... ... @@ -443,7 +443,8 @@ select count(0) from (
}
//type2 对我所在部门公开的机会 公司公开的机会
func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
var filterDepartment string = getFilterSqlByDIds(dIds)
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
... ... @@ -470,11 +471,11 @@ select * from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
) a left JOIN chance_data b on a.id =b.chance_id
order by create_at desc
limit %v
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
... ... @@ -501,8 +502,8 @@ select count(0) from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
... ... @@ -513,9 +514,16 @@ select count(0) from (
}
return
}
func getFilterSqlByDIds(dIds []int) string {
if len(dIds) == 0 {
return ""
}
return fmt.Sprintf(" and department_id in(%v) ", utils.JoinInts(dIds, ","))
}
//type1 禁止查看所有机会
func GetChancePoolMyself(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
func GetChancePoolMyself(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) {
var filterDepartment string = getFilterSqlByDIds(dIds)
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
... ... @@ -529,11 +537,11 @@ select * from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
) a left JOIN chance_data b on a.id =b.chance_id
order by create_at desc
limit %v
`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
... ... @@ -547,8 +555,8 @@ select count(0) from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1
`, uid, uid, chanceTypeId, chanceTypeId)
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
`, uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
... ... @@ -648,3 +656,14 @@ func ExitsChanceByAuditUser(chanceId int64, auditUserId int64) (v *Chance, err e
}
return
}
//是否存在发布机会的部门编号查询
func GetChanceStatisticByDepartment(companyId int64, departmentIds []int, reviewStatus int) (v int, err error) {
sql := fmt.Sprintf(`select count(0) from chance where company_id=%v and review_status=%v and department_id in (%v)`,
companyId, reviewStatus, utils.JoinInts(departmentIds, ","))
o := orm.NewOrm()
if err = o.Raw(sql).QueryRow(&v); err != nil {
return
}
return
}
... ...
... ... @@ -90,3 +90,13 @@ order by parent_id,id`
}
return
}
func GetSubDepartmentIds(companyId int64, relation string) (v []int, err error) {
o := orm.NewOrm()
sql := fmt.Sprintf(`
select id from department where company_id=? and relation like '%v%%' and delete_at =0`, relation)
if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil {
return
}
return
}
... ...
... ... @@ -9,12 +9,13 @@ const (
//成果项
type AchievementItem struct {
Id int64 `json:"id"`
CreateTime int64 `json:"createTime"`
Provider *BaseUserInfo `json:"provider"`
Content string `json:"content"`
Pictures []Picture `json:"pictures"`
GraspScore float64 `json:"graspScore"` //把握分
Id int64 `json:"id"`
CreateTime int64 `json:"createTime"`
Provider *BaseUserInfo `json:"provider"`
Content string `json:"content"`
Pictures []Picture `json:"pictures"`
GraspScore float64 `json:"graspScore"` //把握分
GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比
}
//机会列表 通用项
... ... @@ -105,9 +106,10 @@ type AchievementDetailResponse struct {
}
type UserGraspInfo struct {
Provider *BaseUserInfo `json:"provider"`
GraspScore float64 `json:"graspScore"` //把握分
Type int `json:"type"` //1:把握人 2:提供者
Provider *BaseUserInfo `json:"provider"`
GraspScore float64 `json:"graspScore"` //把握分
GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比
Type int `json:"type"` //1:把握人 2:提供者
}
type SourceChanceItemOrm struct {
... ...
... ... @@ -168,6 +168,7 @@ type ChancePoolRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会
DepartmentId int `json:"departmentId"` //部门编号
}
type ChancePoolResponse struct {
List []CommonListItem `json:"list"`
... ...
... ... @@ -9,6 +9,11 @@ const (
DepartmentAll //公司所有部门
)
const (
StatisticApproved = 1 //统计已审核
StatisticApproving = 2 //统计审核中
)
/*Departments */
type DepartmentsRequest struct {
//Type int `json:"type" valid:"Required"` //1:公司所有部门 2:用户所在部门
... ... @@ -59,3 +64,20 @@ type Department struct {
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"` //已创建的成果 (显示)
}
... ...
... ... @@ -37,6 +37,7 @@ const (
MyAuditChanceWait //我审核的机会-待我审批
MyAuditChancePass //我审核的机会-已通过
MyAuditChanceReturn //我审核的机会-已退回
MyAchievements //我的成就
MyGraspAchievement //我把握的成果
)
... ...
package protocol
/*GetRankList 排行榜*/
type GetRankListRequest struct {
RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜)
RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门)
RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间)
PageIndex int64 `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页)
PageSize int `json:"pageSize" valid:"Required"` //每页数量
}
type GetRankListResponse struct {
Self RankItem `json:"self"` //自己或所在部门的排名分数
Lists []RankItem `json:"lists"` //排名列表
}
type RankItem struct {
Name string `json:"name,omitempty"` //名称
Score string `json:"score"` //分数
Ranking string `json:"ranking"` //排名
}
/*GetRankType */
type GetRankTypeRequest struct {
}
type GetRankTypeResponse struct {
List []RankType
}
type RankType struct {
Id int `json:"id"`
Name string `json:"name"`
}
/*GetRankRange */
type GetRankRangeRequest struct {
}
type GetRankRangeResponse struct {
}
type RankRange struct {
}
/*GetRankPeriods 获取榜单竞争范围列表*/
type GetRankPeriodsRequest struct {
}
type GetRankPeriodsResponse struct {
}
... ...
... ... @@ -311,6 +311,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
beego.ControllerComments{
Method: "DepartmentStatistics",
Router: `/statistics`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"],
beego.ControllerComments{
Method: "GetPlayInfo",
... ... @@ -415,6 +423,38 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankList",
Router: `/getRankList`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankPeriods",
Router: `/getRankPeriods`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankRange",
Router: `/getRankRange`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankType",
Router: `/getRankType`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"],
beego.ControllerComments{
Method: "UCenterLogin",
... ...
... ... @@ -8,7 +8,7 @@ import (
)
//机会池
func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
func GetChancePool(uid, cid int64, chanceTypeId int, departmentId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
var (
check int
checkMap map[int]int
... ... @@ -16,6 +16,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
userDIds []int64
user *models.User
chance *models.Chance
dIds []int
)
if user, err = models.GetUserByCompanyId(cid); err != nil {
log.Error(err)
... ... @@ -43,29 +44,32 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
}
lastId = chance.ApproveTime.Unix()
}
if departmentId > 0 {
dIds, _ = GetDepartmentIds(cid, departmentId)
}
log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid))
switch check {
case OpportunityCheckLv1:
return models.GetChancePoolMyself(uid, cid, chanceTypeId, lastId, pageSize, v)
return models.GetChancePoolMyself(uid, cid, chanceTypeId, dIds, lastId, pageSize, v)
case OpportunityCheckLv2:
if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
log.Error(err)
return
}
return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds)
return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, userDIds)
case OpportunityCheckLv3:
if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会
if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
log.Error(err)
return
}
return models.GetChancePoolDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds, userDIds)
return models.GetChancePoolDepartment(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, specialDIds, userDIds)
}
return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds)
return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, specialDIds)
case OpportunityCheckLv4:
return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
return models.GetChancePoolAll(uid, cid, chanceTypeId, dIds, lastId, pageSize, v)
default:
return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
return models.GetChancePoolAll(uid, cid, chanceTypeId, dIds, lastId, pageSize, v)
}
return
}
... ...
... ... @@ -49,7 +49,7 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8)
//我把握的统计
func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) {
var ()
if total, err = models.GetAchievementAll(header.UserId, header.CompanyId, 0, 0, 0, 0, nil); err != nil {
if total, err = models.GetAchievementAll(header.UserId, header.CompanyId, 0, 0, []int{}, 0, nil); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -59,3 +59,59 @@ func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) {
}
return
}
//我把握的统计
func AchievementDepartmentStatic(header *protocol.RequestHeader, chanceTypeId int, departmentIds []int) (total int, err error) {
//var (
// departmentIds []int
//)
//if dId>0{
// departmentIds,_=GetDepartmentIds(header.CompanyId,dId)
//}
if total, err = models.GetAchievementAll(0, header.CompanyId, chanceTypeId, 0, departmentIds, 0, nil); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
return
}
//机会待审核统计
func ChanceApprovingStatistic(header *protocol.RequestHeader, departmentIds []int) (total int, err error) {
//var (
// departmentIds []int
//)
//if dId>0{
// departmentIds,_=GetDepartmentIds(header.CompanyId,dId)
//}
//if len(departmentIds)==0{
// return
//}
if total, err = models.GetChanceStatisticByDepartment(header.CompanyId, departmentIds, protocol.ReviewStatusAuditging); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
return
}
//获取部门以及子部门编号
func GetDepartmentIds(companyId int64, dId int) (departmentIds []int, err error) {
if d, e := models.GetDepartmentById(dId); e != nil {
log.Error(err)
err = e
return
} else {
if departmentIds, err = models.GetSubDepartmentIds(companyId, d.Relation); err != nil {
log.Error(err)
return
}
}
return
}
... ...
... ... @@ -13,12 +13,25 @@ import (
//成果池
func AchievementPool(header *protocol.RequestHeader, request *protocol.AchievementPoolRequest) (rsp *protocol.AchievementPoolResponse, err error) {
var (
ormItems []protocol.CommAchievementItemOrm
total int
ormItems []protocol.CommAchievementItemOrm
total int
departmentIds []int
)
rsp = &protocol.AchievementPoolResponse{}
rsp.List = make([]*protocol.AchievementCommonListItem, 0)
if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.DepartmentId, request.PageSize, &ormItems); err != nil {
if request.DepartmentId > 0 {
if d, e := models.GetDepartmentById(request.DepartmentId); e != nil {
log.Error(err)
err = e
return
} else {
if departmentIds, err = models.GetSubDepartmentIds(header.CompanyId, d.Relation); err != nil {
log.Error(err)
return
}
}
}
if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, departmentIds, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -52,11 +65,12 @@ func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchiev
return
} else {
item = protocol.AchievementItem{
Id: from.AchievementId,
Provider: provider,
CreateTime: from.CreateTime.Unix() * 1000,
Content: from.SourceContent,
GraspScore: from.GraspScore,
Id: from.AchievementId,
Provider: provider,
CreateTime: from.CreateTime.Unix() * 1000,
Content: from.SourceContent,
GraspScore: from.GraspScore,
GraspScorePercent: from.GraspScore,
}
jsonUnmarshal(from.Images, &item.Pictures)
}
... ... @@ -124,9 +138,10 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
}
newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo {
return protocol.UserGraspInfo{
Provider: user,
GraspScore: score,
Type: t,
Provider: user,
GraspScore: score,
GraspScorePercent: score,
Type: t,
}
}
addParticipants := func(item protocol.UserGraspInfo) {
... ...
... ... @@ -1281,7 +1281,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
rsp = &protocol.ChanceStatisticsResponse{}
for i := range chanceType {
item := chanceType[i]
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil {
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, 0, nil); err != nil {
log.Error(err)
return
}
... ... @@ -1369,7 +1369,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
provider *protocol.BaseUserInfo
flag int
)
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.LastId, request.PageSize, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ...
... ... @@ -2,9 +2,11 @@ package department
import (
"encoding/json"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/models"
"opp/protocol"
"opp/services/agg"
)
func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) {
... ... @@ -56,3 +58,49 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro
}
return nil
}
//部门统计
func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) {
var (
departmentsResponse *protocol.DepartmentsResponse
)
rsp = &protocol.DepartmentStatisticsResponse{}
if departmentsResponse, err = Departments(header, &protocol.DepartmentsRequest{Type: 1}); err != nil && err != orm.ErrNoRows {
log.Error(err)
return
}
departments := departmentsResponse.GetRootDepartment()
iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) {
for i := range departments {
department := departments[i]
item := call(department)
item.Dep = protocol.Dep{
Id: department.DepartmentId,
Name: department.Name,
}
rsp.List = append(rsp.List, item)
}
}
switch request.Type {
case protocol.StatisticApproved:
iterateDepartments(func(d *protocol.Department) *protocol.DepartmentStatistics {
rsp := &protocol.DepartmentStatistics{}
dIds := departmentsResponse.GetChildDepartmentIds(d, true)
rsp.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds)
rsp.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, d.DepartmentId, 0, 0, nil)
return rsp
})
break
case protocol.StatisticApproving:
iterateDepartments(func(d *protocol.Department) *protocol.DepartmentStatistics {
rsp := &protocol.DepartmentStatistics{}
rsp.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, departmentsResponse.GetChildDepartmentIds(d, true))
return rsp
})
break
default:
err = protocol.NewErrWithMessage(2)
return
}
return
}
... ...
package rank
import "opp/protocol"
//排行榜
func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) {
var ()
rsp = &protocol.GetRankListResponse{}
return
}
//获取榜单类型列表
func GetRankType(header *protocol.RequestHeader, request *protocol.GetRankTypeRequest) (rsp *protocol.GetRankTypeResponse, err error) {
var ()
rsp = &protocol.GetRankTypeResponse{}
return
}
//获取榜单范围列表
func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRangeRequest) (rsp *protocol.GetRankRangeResponse, err error) {
var ()
rsp = &protocol.GetRankRangeResponse{}
return
}
//获取排行榜周期列表
func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPeriodsRequest) (rsp *protocol.GetRankPeriodsResponse, err error) {
var ()
rsp = &protocol.GetRankPeriodsResponse{}
return
}
... ...
... ... @@ -434,7 +434,12 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis
log.Error(err)
}
break
case protocol.MyGraspAchievement:
case protocol.MyAchievements: //我提交的
if total, err = agg.MyGraspStatic(header); err != nil {
log.Error(err)
}
break
case protocol.MyGraspAchievement: //我把握的成果
if total, err = agg.MyGraspStatic(header); err != nil {
log.Error(err)
}
... ...