department.go 1.8 KB
package v1

import (
	"encoding/json"
	"opp/controllers"
	"opp/protocol"
	"opp/services/department"

	"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)

type DepartmentController struct {
	controllers.BaseController
}

//Departments
//@router /departments [post]
func (this *DepartmentController) Departments() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.DepartmentsRequest
	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.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.Statistics(header, request))
}

//DepartmentStatistic 单部门统计
//@router /statistic [post]
func (this *DepartmentController) DepartmentStatistic() {
	var msg *protocol.ResponseMessage
	defer func() {
		this.Resp(msg)
	}()
	var request *protocol.DepartmentStatisticRequest
	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.DepartmentStatistic(header, request))
}